例如"123456"输出为"65431"。
方法一:
1 public class Dao{ 2 public static void main(String[]args){ 3 java.util.Scanner input=new java.util.Scanner(System.in); 4 System.out.println("请输入要倒置的数字:"); 5 int a=input.nextInt(); 6 7 while(a!=0){ 8 int b=a%10; 9 System.out.print(b); 10 a=a/10; 11 } 12 } 13 }
方法二:
1 import java.util.Scanner; 2 3 public class Reverse { 4 public static void main(String[] args) { 5 System.out.print("请输入:"); 6 7 String str = String.valueOf(new Scanner(System.in).nextInt()); 8 9 for (int i = str.length() - 1; i >= 0; i--) 10 System.out.print(str.charAt(i)); 11 } 12 }
方法三:
1 import java.util.Scanner; 2 public class Reverse { 3 public static void main(String[] args) { 4 System.out.print("请输入:"); 5 6 Scanner input = new Scanner(System.in); 7 int number = input.nextInt(); 8 System.out.println(new StringBuilder(String.valueOf(number)).reverse()); 9 } 10 }
-