例如: 輸入101,輸出: 1 0 0 0 0 1。
import java.util.Scanner; public class C1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("請輸入一個金額"); int a = input.nextInt(); int b = a / 100 ; int c = ( a - b * 100 ) / 50; int d = ( a - b * 100 - c * 50 ) / 20 ; int e = ( a - b * 100 - c * 50 - d * 20) / 10; int f = ( a - b * 100 - c * 50 - d * 20 - e * 10 ) / 5; int g = ( a - b * 100 - c * 50 - d * 20 - e * 10 - f * 5 ) / 1; System.out.print(b); System.out.print(c); System.out.print(d); System.out.print(e); System.out.print(f); System.out.print(g); } }
沒有留言:
張貼留言