题解 | #数字颠倒#
数字颠倒
http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
/* JAVA 两种解法: 1,对这个整数取模,依次得到个位数的值,拼接成字符串 2,把整数转成字符串,反向遍历。 */ import java.util.Scanner; //解法1 public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int a = in.nextInt(); StringBuffer sb = new StringBuffer(); String result = ""; while(a!=0){ sb.append(a%10); a /= 10; } System.out.print(sb.toString()); } } // //解法2 // public class Main { // public static void main(String[] args){ // Scanner in = new Scanner(System.in); // int a = in.nextInt(); // String str = String.valueOf(a); // for(int i= str.length() -1;i>=0;i--){ // System.out.print(str.charAt(i)); // } // } // }