输入一个数,判断位数并倒序输出
package com.baidu.zhidao;
import java.util.Scanner;
public class InvertedOrder {
public static void main(String[] args) {
while (true) {
try {
System.out.print("Type in a number:");
String str = "";
Scanner s = new Scanner(System.in);
char[] ch = s.next().toCharArray();
System.out.println("The number length is: " + ch.length + " !");
for(int i = ch.length-1;i>=0;i--){
str+=ch[i];
}
System.out.print("Inverted order number is:" + str +" \n");
} catch (Exception e) {
// TODO: handle exception
}
}
}
}