思路:采用StringBuffer进行拼接
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String str=new String();
str=n+"";//整数转为字符串
StringBuffer sb=new StringBuffer();
for(int i=str.length()-1;i>=0;i--){
char b=str.charAt(i);
sb.append(b);
}
System.out.println(sb.toString());
}
}
num%10取得个位数,
Num/10进入下一轮循环
import java.util.*;
public class Main{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
String res="";
while(num!=0){
int t1=num%10;
int t2=num/10;
res=res+t1;
num=t2;
}
System.out.println(res);
}
}