Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class testMoneyBox {
- public static void main(String[] args) {
- MoneyBox moneyBox = new MoneyBox();
- moneyBox.run();
- moneyBox.show();
- }
- }
- class MoneyBox {
- private int n;
- private int sum;
- private Scanner sc = new Scanner(System.in);
- private int[][] box = {{1000, 0}, {5000, 0}, {10000, 0}};
- public void run() {
- while (true) {
- System.out.print("額面を入力: ");
- n = sc.nextInt();
- if (n == 0) {
- return;
- }
- if (n != 1000 && n != 5000 && n != 10000) {
- System.out.println("お札ではありません。");
- continue;
- }
- put(n);
- }
- }
- private void put(int money) {
- switch (money) {
- case 1000:
- box[0][1]++;
- break;
- case 5000:
- box[1][1]++;
- break;
- case 10000:
- box[2][1]++;
- break;
- }
- }
- public void show() {
- for (int i = 0; i < box.length; i++) {
- System.out.printf("%d円札の数:%d\n", box[i][0], box[i][1]);
- sum += box[i][0] * box[i][1];
- }
- System.out.printf("合計は%d円\n", sum);
- }
- }
Add Comment
Please, Sign In to add comment