Java语法练习:String和Int、Double、Boolean的相互转换
public class TpyeConversion {
public static void main(String[]args){
String str1 = String.valueOf(111);
String str2 = String.valueOf(111.5);
String str3 = String.valueOf(true);
String str4 = Integer.toString(222);
String str5 = Double.toString(222.5);
String str6 = Boolean.toString(false);
try {
int a1 = Integer.parseInt(str1);
System.out.println(a1+1);
double a2 =Double.parseDouble(str2);
System.out.println(a2);
boolean a3 = Boolean.parseBoolean(str3);
System.out.println(a3);
} catch (NumberFormatException e) {
e.printStackTrace();
}
try {
int a4 = Integer.valueOf(str4).intValue();
System.out.println(a4+1);
double a5 = Double.valueOf(str5).doubleValue();
System.out.println(a5);
boolean a6 = Boolean.valueOf(str6).booleanValue();
System.out.println(a6);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}