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:
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); } }
Enter the Amount : 158388 Total Number of Notes 500 = 316 100 = 3 50 = 1 20 = 1 10 = 1 5 = 1 2 = 1 1 = 1
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions