题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
package cn.ls.lanqiao;
import java.util.*;
public class Test24 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
converse(n);
/*
* for (int i = n.length() - 1; i >= 0; i--) { System.out.print(n.charAt(i)); }
*/
}
public static void converse(int n) {
String s = Integer.toString(n);
System.out.println(n + "是" + s.length() + "位数");
char[] ch = s.toCharArray();
for (int i = ch.length - 1; i >= 0; i--) {
System.out.print(ch[i]);
}
}
}