在Java中用while.颠倒数据:
1 package Cforth; 2 3 import java.util.*; 4 5 public class C4_13 { 6 public static void main(String[] args) { 7 8 Scanner in = new Scanner(System.in); 9 System.out.println("请输入一个整数:"); 10 int number = in.nextInt(); 11 while (number != 0) { 12 int value = number % 10; 13 System.out.print(value); 14 number = number / 10; 15 } 16 System.out.print(" 数值被颠倒!"); 17 } 18 }
测试结果如下:
测试成功!