import java.util.Scanner; //imports Scanner util public class MinimumCoins { public static void main(String[] args) { Scanner input = new Scanner(System.in); //creates an instance of a class called input // sets inintial variables int Ammount,QuarterCount = 0,DimeCount = 0,NickelCount = 0,PennieCount; System.out.println("Please Enter ammount of change (1-99) "); //prints message Ammount = input.nextInt(); // reads ammount of change while (Ammount > 25) { Ammount = Ammount - 25; QuarterCount++; } //while this condition is true it will subtract 25 and add 1 to the quarter counter while (Ammount > 10) { Ammount = Ammount - 10; DimeCount++; }// while this is true it will subtract 10 from ammount and add 1 to the dime counter while (Ammount > 5) { Ammount = Ammount - 5; NickelCount++; }// while this is true it will subtract 5 from ammount and add 1 to the nickle counter System.out.println("Quarters: " + QuarterCount); // printers quarters System.out.println("Dimes: " + DimeCount); // prints dimes System.out.println("Nickles: " + NickelCount); // prints nickels System.out.println("Pennies: " + Ammount); // prints pennies or remaining ammount } // end of main () } //end of MinimumCoins class
I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More