Skip to content

Instantly share code, notes, and snippets.

@tomrlh
Created February 23, 2019 17:34
Show Gist options
  • Save tomrlh/903911e33d352e95b597c7bc516a187e to your computer and use it in GitHub Desktop.
Save tomrlh/903911e33d352e95b597c7bc516a187e to your computer and use it in GitHub Desktop.
IntentionalWoodenStacks created by tomrlh - https://repl.it/@tomrlh/IntentionalWoodenStacks
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]));
}
}
}
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