import java.util.Scanner;
public class sy3_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个不超过5位的正整数:");
int num = sc.nextInt();
int c = 1;
for(int i = 10 ; i <= 10000; i = i*10) {
if(num % i != num) {
c++;
}
}
System.out.println("整数的位数是:" + c + "位");
String s = num + "";
char[] s1 = s.toCharArray();
System.out.println("逆序输出各位数字:");
for(int i = s1.length - 1;i >= 0; i--) {
System.out.print(s1[i] + " ");
}
}
}
2.给一个不多于5位的正整数,要求:1)求出它是几位数;2)分别输出每一位数字;3) 按逆序输出各位数字,例如原数是321,应输出123。#java
最新推荐文章于 2024-09-10 10:21:38 发布