Java中String和Int类相互转换的方法

String Sch_No = "1707020410";
int output = Integer.parseInt(Sch_No);

这样就将学号“1707020410” 转换成了纯数字1707020410

其他的也是类似的

double d = Double.parseDouble(String a);
float f = Float.parseFloat(String s);

反过来的话,将数字转换为字符串,就要用到String类中的valueof方法

String s = String.valueof(7);
//输出s为"7"

其他类型的同理。

猜你喜欢

转载自blog.csdn.net/Leonards_1998/article/details/85336264