例如:輸入4567,輸出4 5 6 7 。
import java.util.Scanner;
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("請輸入數字(介於1到32767):");
int number = input.nextInt();
int remainder = number;
int quotient = 0;//商數
String output = " ";
//計算結果
while( number > 0 )
{
remainder = number % 10;//餘數
quotient = number / 10;//商數
number = quotient;
output = remainder + " " + output;
}
System.out.println(output);
}
沒有留言:
張貼留言