Created
February 23, 2019 17:34
-
-
Save tomrlh/903911e33d352e95b597c7bc516a187e to your computer and use it in GitHub Desktop.
IntentionalWoodenStacks created by tomrlh - https://repl.it/@tomrlh/IntentionalWoodenStacks
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
import java.util.Scanner; | |
public class CoinTypesGenerator { | |
public static void main(String []args){ | |
System.out.println("Enter a number: "); | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
// coinTypes contain the number to be divided for, singular and plural names for each type of coin | |
String[][] coinTypes = {{"200", "toony", "toonies"}, {"100", "loony", "loonies"}, {"25", "quarter", "quarters"}, {"10", "dime", "dimes"}, {"5", "nickel", "nickels"}, {"1", "penny", "pennie"}}; | |
for(String[] coin : coinTypes) { | |
int convertedCoin = (n / Integer.parseInt(coin[0])); | |
if(convertedCoin > 0) // this is just to check if the value is higher then 0, if not, nothing is printed | |
System.out.println("That is " + convertedCoin + " " + (convertedCoin > 1 ? coin[2] : coin[1])); | |
} | |
} | |
} |
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
import java.util.Scanner; | |
public class Main{ | |
public static void main(String []args){ | |
System.out.println("Enter a number: "); | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
String[][] coinTypes = {{"200", "toony", "toonies"}, {"100", "loony", "loonies"}, {"25", "quarter", "quarters"}, {"10", "dime", "dimes"}, {"5", "nickel", "nickels"}, {"1", "penny", "pennie"}}; | |
for(String[] coin : coinTypes) { | |
int convertedCoin = (n / Integer.parseInt(coin[0])); | |
System.out.println(convertedCoin | |
); | |
if(convertedCoin > 0) | |
System.out.println("That is " + convertedCoin + " " + (convertedCoin > 1 ? coin[2] : coin[1])); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment