Created
April 10, 2020 13:52
-
-
Save mina93612/d447affec9c6566de4bf0ac71e3c8cd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fju; | |
import java.sql.SQLOutput; | |
import java.util.Scanner; | |
public class PiggyBank { | |
public static void main(String[] args) { | |
Scanner scanner =new Scanner(System.in); | |
int coin = 0; | |
int newcoin; | |
try { | |
System.out.println("Please throw in the coin~"); | |
coin = Integer.parseInt(scanner.nextLine()); | |
} catch (NumberFormatException e) { | |
System.out.println("wrong format!"); | |
e.printStackTrace(); | |
} | |
if (coin==1||coin==5||coin==10){ | |
System.out.println("Total is " + coin + "! Keep going!"); | |
while (coin==1||coin==5||coin==10){ | |
newcoin = Integer.parseInt(scanner.nextLine()); | |
int deposit =coin+newcoin; | |
System.out.println("Total is " + deposit + "! Keep going!"); | |
} | |
}else System.out.println("wrong format!"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment