• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

Java Minimum Coins Program, How to maximise your change skills?

October 17, 2012 by Rick Hernandez Leave a Comment

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


Rick Hernandez

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

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: Java, Programming

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in