7-3 逆序的三位数(10 分)
程序每次读入一个正3位数,然后输出按位逆序的数字。注意:当输入的数字含有结尾的0时,输出不应带有前导的0。比如输入700,输出应该是7。
输入格式:
每个测试是一个3位的正整数。
输出格式:
输出按位逆序的数。
输入样例:
123
输出样例:
321
import java.util.Scanner;
public class Main {
public static void main(String[] args){
/*
Scanner sc =new Scanner(System.in);
String str=sc.next();
char[] array=str.toCharArray();//将此字符串转换为字符数组
int j=0;
if(array[j]=='0'){
j++;
for(;j<str.length();j++){
if(array[j]!='0'){
System.out.print(array[j]);
}
}
}
else{
for(int i=0;i<str.length();i++){
System.out.print(array[str.length()-1-i]);
}
}*/
int b, c, d = 0;
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
b = num / 100;
num %= 100;
c = num / 10;
num %= 10;
d = num / 1;
if(b==0 && c!=0){
int result=d*100+c*10;
System.out.print(result);
}else if(b==0 && c==0){
int result=d;
System.out.print(result);
}
else{
int result=d*100+c*10+b;
System.out.print(result);
}
}
}