Reverse an integer with only three digits
The first introductory question in lintcode, the method given in the question is not of static type, so when the main function is called, an object of this method needs to be created. The code has been commented.
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("输入错误,请输入一个三位数");
}
}
}