Write a program to count total number of notes in given amount


This program takes an input amount and then calculates the number of each type of currency note required to arrive at that amount. It uses a series of if statements to determine how many of each note is required.

Here's how it works:

  • The program prompts the user to enter the amount.
  • It then initializes variables for the number of each type of note, all set to 0.
  • The program then checks if the amount is greater than or equal to 500. If it is, it calculates the number of 500 rupee notes required, subtracts the value of those notes from the total amount, and sets the n500 variable to the calculated value. This process is repeated for the remaining denominations of notes.
  • Finally, the program prints the total number of notes required for each denomination.

Source Code

import java.util.Scanner;
class Count_Total_Number
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter the Amount :");
		int amt = input.nextInt();
		int n500, n100, n50, n20, n10, n5, n2, n1;
		n500 = n100 = n50 = n20 = n10 = n5 = n2 = n1 = 0;
		if(amt >= 500)
			n500 = amt/500;
			amt -= n500 * 500;
		if(amt >= 100)
			n100 = amt/100;
			amt -= n100 * 100;
		if(amt >= 50)
			n50 = amt/50;
			amt -= n50 * 50;
		if(amt >= 20)
			n20 = amt/20;
			amt -= n20 * 20;
		if(amt >= 10)
			n10 = amt/10;
			amt -= n10 * 10;
		if(amt >= 5)
			n5 = amt/5;
			amt -= n5 * 5;
		if(amt >= 2)
			n2 = amt /2;
			amt -= n2 * 2;
		if(amt >= 1)
			n1 = amt;
 
		System.out.println("Total Number of Notes");
		System.out.println("500 = "+ n500);
		System.out.println("100 = "+ n100);
		System.out.println("50 = "+ n50);
		System.out.println("20 = "+ n20);
		System.out.println("10 = "+ n10);
		System.out.println("5 = "+ n5);
		System.out.println("2 = "+ n2);
		System.out.println("1 = "+ n1);
	}
}

Output

Enter the Amount :
158388
Total Number of Notes
500 = 316
100 = 3
50 = 1
20 = 1
10 = 1
5 = 1
2 = 1
1 = 1

Example Programs