题目:求一个长整数的各位数字是多少并输出?
示例代码:
package cn.wdl.demo;import java.util.Scanner;public class Case04 {public static void main(String[] args) {// 求一个长整数的各位数字是多少并输出?long num = 0;Scanner sc = new Scanner(System.in);System.out.println("请输入一个长整数:");num = sc.nextLong();long tmp = num/10;while(num>0) {System.out.print((num - tmp*10)+" ");num = num/10;tmp = num/10;}}}
运行结果:
请输入一个长整数:
1234567890
0 9 8 7 6 5 4 3 2 1