Home »
Java Programs »
Java Basic Programs
Java program to count number of notes (rupees) in given amount
Here, we are implementing a java program that will read an amount and then convert, count total number of different notes (rupees).
Submitted by Chandra Shekhar, on January 08, 2018
Problem statement
Given an amount and we have to count total number of different notes (rupees) using java program.
Example
Input:
Amount is: 54206
Output:
Notes of:
1000 - 54
100 – 2
5 -1
1 -1
Total number of notes is: 58
Program to count number of different notes in java
import java.io.*;
class CountNotes
{
public static void main(String args[])throws IOException
{
// create object of buffer class.
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
// The Rsominations in an array
int Rs[]={1000,500,100,50,20,10,5,2,1};
// enter the amount you want.
System.out.print("Enter any Amount : ");
// to store amount.
int amount=Integer.parseInt(br.readLine());
// create copy of the amount
int copy=amount;
int totalNotes=0,count=0;
System.out.println("\nRs OMINATIONS : \n");
// check for notes.
for(int i=0;i<9;i++)
{
// count 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; //finding the total number of notes
amount=amount%Rs[i]; //finding the remaining amount whose Rsomination is to be found
}
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);
}
}
Output
Enter any Amount : 54206
Rs OMINATIONS :
1000 x 54 = 54000
100 x 2 = 200
5 x 1 = 5
1 x 1 = 1
--------------------------------
TOTAL = 54206
--------------------------------
Total Number of Notes = 58
Java Basic Programs »