Java经典习题24

/*
题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
*/

import java.util.*;

public class Class24 {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入一个不多于5位的正整数:");
Scanner sc = new Scanner(System.in);
int s = sc.nextInt();
int length = 5;
int count = 0;
double temp = 0;
for(int i = 1; i < length + 1; i++){
if((int)(s / (Math.pow(10,(i - 1)))) != 0){
count++;
}
}
System.out.println("该数字的位数为:");
System.out.println(count);
System.out.println("逆序输出该数字");
String a= String.valueOf(s);
char ch[] = a.toCharArray();
for(int j = count-1; j >= 0; j--){
System.out.print(ch[j]);
}

}

}

原文地址:https://www.cnblogs.com/zhuozige/p/12358674.html