反转一个只有三位的整数
lintcode中的入门题第一道,题中给出的方法不是static类型,所以在主函数调用时,需要创建该方法的对象。代码已被注释。
public class Solution {
public static int reverseInteger(int number) {
int a,b,c,t;
a = number / 100;
b = (number - a*100)/10;
c = number % 10;
// t = a;
// a = c;
// c = t;
//int num = (a*100)+(b*10)+c;
int num = (c*100)+(b*10)+a;
return num;
}
public static void main(String [] args){
System.out.print("输入:");
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
//Solution so = new Solution();
if(number > 100 && number < 1000){
//System.out.print("输出:"+ so.reverseInteger(number));
System.out.print("输出:"+ reverseInteger(number));
}
else{
System.out.print("输入错误,请输入一个三位数");
}
}
}