问题及代码:
输入一个整数,再反向输出。
例:输入3456,输出6543
import java.util.Scanner;
public class reversal {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("please enter an integer: ");
Scanner input = new Scanner(System.in);
int num = input.nextInt();
reverse(num);
}
public static void reverse(int number) {
int j;
System.out.print("the number's reversal is ");
while (number != 0) {
j = number % 10;
System.out.print(j);
number = number / 10;
}
}
}
运行结果: