题解 | #数字颠倒#
数字颠倒
http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
方法1
import java.util.*;
public class Main{
public static int[] s1 = new int[128];
public static void main(String[] args){
Scanner in = new Scanner(System.in);
Long a = in.nextLong();
Long temp = 0L;
if(a == 0){
System.out.println(a);
}
else{
while(a != 0){
temp = a%10;
a = a/10;
System.out.print(temp);
}
}
}
}
方法2
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
Long a = in.nextLong();
String str = "" + a;
for(int i = str.length()-1; i >= 0; i--){
System.out.print(str.charAt(i));
}
}
}