黑马程序员技术交流社区
标题:
怎么把一个多位数中每个位上的数表示出来
[打印本页]
作者:
木丶子李
时间:
2016-3-31 14:26
标题:
怎么把一个多位数中每个位上的数表示出来
如题,求教怎么把一个多位数中的每个位上的数表示出来,有几种方法
作者:
淡然无味
时间:
2016-3-31 15:37
例如:153
百位数:153/100 两个int类型数相除得到的结果肯定是int类型的,所以这里是 1
十位数:153/10%10 先除以10 ,得到15,然后在%10 求出余数,所以得到5
个位数:153%10 直接除以%10,得到个位数
作者:
木丶子李
时间:
2016-4-1 16:32
淡然无味 发表于 2016-3-31 15:37
例如:153
百位数:153/100 两个int类型数相除得到的结果肯定是int类型的,所以这里是 1
十位数:153/10 ...
非常感谢!!
作者:
菊花爆满山
时间:
2016-4-1 16:51
package com.heima.demo;
import java.math.BigInteger;
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//用这个类是防止数太大 超过了long的取值范围
BigInteger b = new BigInteger(Integer.parseInt(sc.nextLine()) +"");
String str = b.toString();
for(int x = 0; x < str.length(); x++) {
System.out.println(str.charAt(x));
}
sc.close();
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2