PROGRAM 10 : ENTER AN AMOUNT TO FIND THE DENOMINATIONS OF AMOUNT
Example:
PROGRAM:
import java.util.Scanner;
public class denominationofamount
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter an amount to find out it's denominations:");
int num = sc.nextInt() ;
int copy = num;
int deni[] = {1000 , 500 ,100 , 50 , 20 , 10 , 5 , 2 , 1}; // ARRAY STORES THE DENOMINATION VALUES
int totalnumberofnotes = 0; // STORES THE NUMBER OF NOTES
int count;
System.out.println("\nDENOMINATIONS:\n");
for(int i = 0 ; i<9 ; i++)
{
count = num/deni[i]; // DIVIDES NUMBER ACCORDING TO ELEMENT NUMBER IN ARRAY
if(count!=0) // CHECKS THAT THE DIGIT IS NOT A ZERO
System.out.println(deni[i] + "\tX\t" + count + "\t=\t" + (deni[i]*count));
totalnumberofnotes+=count;
num = num%deni[i]; // LEAVES A REMAINDER WHICH IS USED FURTHER
}
System.out.println("-----------------------------------------------------------------");
System.out.println("TOTAL AMOUNT = " + copy);
System.out.println("-----------------------------------------------------------------");
System.out.println("TOTAL NUMBER OF NOTES = " + totalnumberofnotes);
}
}
Example:
PROGRAM:
import java.util.Scanner;
public class denominationofamount
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter an amount to find out it's denominations:");
int num = sc.nextInt() ;
int copy = num;
int deni[] = {1000 , 500 ,100 , 50 , 20 , 10 , 5 , 2 , 1}; // ARRAY STORES THE DENOMINATION VALUES
int totalnumberofnotes = 0; // STORES THE NUMBER OF NOTES
int count;
System.out.println("\nDENOMINATIONS:\n");
for(int i = 0 ; i<9 ; i++)
{
count = num/deni[i]; // DIVIDES NUMBER ACCORDING TO ELEMENT NUMBER IN ARRAY
if(count!=0) // CHECKS THAT THE DIGIT IS NOT A ZERO
System.out.println(deni[i] + "\tX\t" + count + "\t=\t" + (deni[i]*count));
totalnumberofnotes+=count;
num = num%deni[i]; // LEAVES A REMAINDER WHICH IS USED FURTHER
}
System.out.println("-----------------------------------------------------------------");
System.out.println("TOTAL AMOUNT = " + copy);
System.out.println("-----------------------------------------------------------------");
System.out.println("TOTAL NUMBER OF NOTES = " + totalnumberofnotes);
}
}
No comments:
Post a Comment