Write a java program to count total number of notes in entered amount using loop

Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.io.*;
 
class Javaexcercise
{
    public static void main(String args[])throws IOException
    {		
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));		
 
        int Rs[]={1000,500,100,50,20,10,5,2,1}; 
 
        System.out.print("Enter any Amount : "); 
                int amount=Integer.parseInt(br.readLine()); 
 
        int copy=amount; 
        int totalNotes=0,count=0;
 
        System.out.println("\nRs OMINATIONS : \n");
 
        for(int i=0;i<9;i++) 
        {
            // counting number of notes.
            count=amount/Rs[i]; 
            if(count!=0) 
            {
                System.out.println(Rs[i]+"\tx\t"+count+"\t= "+Rs[i]*count);
            }
            totalNotes=totalNotes+count; 
            amount=amount%Rs[i]; 
        }
 
        System.out.println("--------------------------------");
 
        // printing the total amount
        System.out.println("TOTAL\t\t\t= "+copy); 
        System.out.println("--------------------------------");
 
        // printing the total number of notes
        System.out.println("Total Number of Notes\t= "+totalNotes); 
    }
}

Result

Write a java program to count total number of notes in entered amount using loop
Write a java program to count total number of notes in entered amount using loop

Leave a Comment