📄 j02050306.java
字号:
import java.lang.*;
class j02050306
{
public static void main(String para[])
{
try
{
boolean Bool1 = Boolean.valueOf("fish").booleanValue(); //先 String 转成 Boolean 对象,再取得它的 boolean 值
//不是 "true" (但大小写不论),就为 false
System.out.println("Bool1 = " + Bool1);
Bool1 = Boolean.valueOf("True").booleanValue();
System.out.println("Bool1 = " + Bool1);
String Str1 = "126";
byte B1 = Byte.parseByte("20"); //B1 = 20
System.out.println("B1 = " + B1);
short S1 = Short.parseShort(Str1); //S1 = 126
System.out.println("S1 = " + S1);
int I1 = Integer.parseInt(Str1); //I1 = 126
System.out.println("I1 = " + I1);
long L1 =Long.parseLong(Str1); //L1 = 126
System.out.println("L1 = " + L1);
float F1 = Float.parseFloat(Str1); //F1 = 126.0
System.out.println("F1 = " + F1);
double D1 = Double.parseDouble(Str1); //D1 = 126.0
System.out.println("D1 = " + D1);
S1 = Short.parseShort("332.81");
//字义不属于 0 ~ 65535,产生例外
System.out.println("S1 = " + S1); //在例外之后不会执行
}
catch(NumberFormatException Obj)
{
System.out.println("NumberFormatException happens");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -