The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
Use the API documentation to find the answers to the following questions:使用API文档查找以下问题的答案:
What 您可以使用什么Integer
method can you use to convert an int
into a string that expresses the number in hexadecimal?Integer
方法将int
转换为以十六进制表示数字的字符串?For example, what method converts the integer 65 into the string "41"?例如,什么方法将整数65转换为字符串“41”?
What 您将使用什么Integer
method would you use to convert a string expressed in base 5 into the equivalent int
?Integer
方法将以基数5表示的字符串转换为等效的int
?For example, how would you convert the string "230" into the integer value 65?例如,如何将字符串“230”转换为整数值65?Show the code you would use to accomplish this task.显示用于完成此任务的代码。
What Double method can you use to detect whether a floating-point number has the special value Not a Number (您可以使用什么NaN
)?Double
方法来检测浮点数是否具有特殊值非数字(NaN
)?
What is the value of the following expression, and why?以下表达式的值是什么,为什么?
Integer.valueOf(1).equals(Long.valueOf(1))
Change 更改MaxVariablesDemo
to show minimum values instead of maximum values.MaxVariablesDemo
以显示最小值而不是最大值。You can delete all code related to the variables 您可以删除与变量aChar
and aBoolean
.aChar
和aBoolean
相关的所有代码。What is the output?输出是什么?
Create a program that reads an unspecified number of integer arguments from the command line and adds them together.创建一个程序,从命令行读取未指定数量的整数参数,并将它们相加。For example, suppose that you enter the following:例如,假设您输入以下内容:
java Adder 1 3 2 10
The program should display 程序应显示16
and then exit.16
,然后退出。The program should display an error message if the user enters only one argument.如果用户只输入一个参数,程序应显示错误消息。You can base your program on 您可以基于ValueOfDemo
.ValueOfDemo
编写程序。
Create a program that is similar to the previous one but has the following differences:创建一个与上一个类似但有以下区别的程序:
For example, suppose that you enter the following:例如,假设您输入以下内容:
java FPAdder 1 1e2 3.0 4.754
The program would display 程序将显示108.75
.108.75
。Depending on your locale, the decimal point might be a comma (根据您的区域设置,小数点可能是逗号(,
) instead of a period (.
).,
)而不是句点(.
)。