JAVA朴素解法-多类型
数字颠倒
http://www.nowcoder.com/questionTerminal/ae809795fca34687a48b172186e3dafe
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in=new Scanner(System.in); int a=in.nextInt(); System.out.println(getString3(a));// //getString1(a); } public static String getString(int a){ StringBuilder res=new StringBuilder(); while(a!=0){ res.append(String.valueOf(a%10)); a=a/10; } return res.toString(); } public static String getString0(int a){ StringBuffer res=new StringBuffer(a); res.reverse(); return res.toString(); } public static void getString1(int a){ String str = Integer.toString(a);//int -> String 的三个方法都ok char[] chararr = str.toCharArray(); for(int i=0;i<chararr.length;i++){ System.out.print(chararr[chararr.length-1-i]); } return ; } public static String getString2(int a){ String str = Integer.toString(a);//int -> String 的三个方法都ok char[] chararr = str.toCharArray(); for(int i=0;i<chararr.length/2;i++){ char tmp=chararr[i]; chararr[i]=chararr[chararr.length-1-i]; chararr[chararr.length-1-i]=tmp; } return new String(chararr); } public static String getString3(int a){ String str = Integer.toString(a);//int -> String 的三个方法都ok char[] chararr = str.toCharArray(); StringBuilder res=new StringBuilder(); for(int i=0;i<chararr.length;i++){ res.append(String.valueOf(chararr[chararr.length-1-i])); } return res.toString(); } }