Q:

Java program to count number of notes (rupees) in given amount

belongs to collection: Java Basic Programs

0

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

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to read marks between 1 to 100 (An Ex... >>
<< Java program to check Emrip number...