Displaying an integer reverse(整数倒置,不受位数限制)
问题及代码:
package first;
import java.util.Scanner;
public class text {
public static void main(String[] args) {
System.out.println("请输入一个整数:");
Scanner get = new Scanner(System.in);
int a = get.nextInt();
int sum = 0;
while (a != 0) {
int b = a % 10;
sum = sum * 10 + b;
a = a / 10;
}
System.out.println(+sum);
}
}
运行结果:
还没有评论,来说两句吧...