Java Program to Find Total Notes in a Given Amount

In the previous article, we have seen Java Program to Calculate Total Amount After Adding Tax

In this article we will see how we can find total notes in a given amount by using Java programming language. How to do Java Program To Count Total Number Of Notes In Given Amount and Java Program To Find The Number Of Denominations For A Given Amount all are described below.

Java Program to Find Total Notes in a Given Amount

In India, Currency notes are available in different denominations like 10 rupees note, 20 rupees note, 50 rupees note, 100 rupees note, 500 rupees note, 2000 rupees note.

In this program first we have found out from greater amount of notes towards lower amount notes.

For example total amount is 2000 so we will print total number of 2000 thousand notes are 2 but not 4 notes of 500 rupees or 20 notes of 100 rupees like this. Means calculation will goes from higher amount notes to lower amount notes.

Let’s see different ways to find total notes in a given amount.

Method-1: Java Program to Find Total Notes in a Given Amount By Using Static Input Value

Approach:

  • Declare total amount.
  • Declare various notes in an array. Total 8 types of notes so array elements are 2000, 500, 100, 50, 20, 10, 5, 2, 1.
  • Take a for loop and iterate 9 times.
  • During each iteration divide total amount with each array element means(with different notes) and keep on printing number of notes in given amount as result.

Program:

import java.util.Scanner; 

 public class Main
 { 
      public static void main(String[] args) 
      { 
          
        //total amount declared
        int totalAmount=9099;
        
        //different types of note value stored in an array
        int arr[] = {2000, 500, 100, 50, 20, 10, 5, 2, 1};

        int temp = totalAmount;
  
        for(int i = 0; i < 8; i++)
        {
            System.out.println("Number of "+arr[i]+" notes = "+temp / arr[i]);
 	        temp = temp % arr[i];
        }
          
      } 
 }
Output:

Number of 2000 notes = 4
Number of 500 notes = 2
Number of 100 notes = 0
Number of 50 notes = 1
Number of 20 notes = 2
Number of 10 notes = 0
Number of 5 notes = 1
Number of 2 notes = 2

Method-2: Java Program to Find Total Notes in a Given Amount By Using User Input Value

Approach:

  • Take total amount as user input using Scanner class.
  • Declare various notes in an array. Total 8 types of notes so array elements are 2000, 500, 100, 50, 20, 10, 5, 2, 1.
  • Take a for loop and iterate 9 times.
  • During each iteration divide total amount with each array element means(with different notes) and keep on printing number of notes in given amount as result.

Program:

import java.util.Scanner; 

 public class Main
 { 
      public static void main(String[] args) 
      { 
        //Scanner class object created
        Scanner sc =new Scanner(System.in);
        int arr[] = {2000, 500, 100, 50, 20, 10, 5, 2, 1};
        int totalAmount;
 
        System.out.print("Enter total amount  =  ");
        totalAmount=sc.nextInt();
 
        int temp = totalAmount;
  
        for(int i = 0; i < 9; i++)
        {
            System.out.println("Number of "+arr[i]+" notes = "+temp / arr[i]);
 	        temp = temp % arr[i];
        }
          
      } 
 }
Output:

Enter total amount = 6687
Number of 2000 notes = 3
Number of 500 notes = 1
Number of 100 notes = 1
Number of 50 notes = 1
Number of 20 notes = 1
Number of 10 notes = 1
Number of 5 notes = 1
Number of 2 notes = 1
Number of 1 notes = 0

Method-3: Java Program to Find Total Notes in a Given Amount By Using User Defined Method

Approach:

  • Take total amount as user input using Scanner class.
  • Declare various notes in an array. Total 8 types of notes so array elements are 2000, 500, 100, 50, 20, 10, 5, 2, 1.
  • Then call a method findNote() by passing the array and total amount as parameter.
  • Inside method take a for loop and iterate 9 times.
  • During each iteration divide total amount with each array element means(with different notes) and keep on printing number of notes in given amount as result.

Program:

import java.util.Scanner; 

 public class Main
 { 
      public static void main(String[] args) 
      { 
        //Scanner class object created
        Scanner sc =new Scanner(System.in);
        int arr[] = {2000, 500, 100, 50, 20, 10, 5, 2, 1};
        int totalAmount;
 
        System.out.print("Enter total amount  =  ");
        totalAmount=sc.nextInt();
        
        //calling user defined method findNote()
        findNote(totalAmount,arr);
      }
      
      //findNote() method to find number of notes  
      public static void findNote(int totalAmount, int[] arr)  
      {
        int temp = totalAmount;
  
        for(int i = 0; i < 9; i++)
        {
            System.out.println("Number of "+arr[i]+" notes = "+temp / arr[i]);
 	        temp = temp % arr[i];
        }
          
      } 
 }
Output:

Enter total amount = 7896
Number of 2000 notes = 3
Number of 500 notes = 3
Number of 100 notes = 3
Number of 50 notes = 1
Number of 20 notes = 2
Number of 10 notes = 0
Number of 5 notes = 1
Number of 2 notes = 0
Number of 1 notes = 1

Want to excel in java coding? Practice with these Java Programs examples with output and write any kind of easy or difficult programs in the java language.

Solve these examples:

  1. Write A Java Program To Count Total Number Of Notes In Given Amount?
  2. Write A Program To Count Total Number Of Notes In Given Amount In Java?
  3. Write A Java Program To Count Total Number Of Notes In Given Amount?
  4. Write A Python Program To Count Total Number Of Notes In Given Amount Using If Else?

Related Java Programs: