步骤 1 :
数字转字符串
顶折
方法1: 使用String类的静态方法valueOf
方法2: 先把基本类型装箱为对象,然后调用对象的toString
代码比较复制代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package digit; public class TestNumber { public static void main(String[] args) { int i = 5 ; //方法1 String str = String.valueOf(i); //方法2 Integer it = i; String str2 = it.toString(); } } |
步骤 2 :
字符串转数字
顶折
调用Integer的静态方法parseInt
代码比较复制代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
package digit; public class TestNumber { public static void main(String[] args) { String str = "999" ; int i= Integer.parseInt(str); System.out.println(i); } } |