Display the denomination of an input amount.
import java.util.Scanner;
class denomination
{
public static void main(String arg[])
{
Scanner input=new Scanner(System.in);
int amount,counts=0;
System.out.println("Enter Amount: ");
amount=input.nextInt();
for(int i=amount;i>=1000;i-=1000)
{
counts++;
amount-=1000;
}
if(counts!=0)
System.out.println("1000 X "+counts);
counts=0;
for(int i=amount;i>=500;i-=500)
{
counts++;
amount-=500;
}
if(counts!=0)
System.out.println("500 X "+counts);
counts=0;
for(int i=amount;i>=100;i-=100)
{
counts++;
amount-=100;
}
if(counts!=0)
System.out.println("100 X "+counts);
counts=0;
for(int i=amount;i>=50;i-=50)
{
counts++;
amount-=50;
}
if(counts!=0)
System.out.println("50 X "+counts);
counts=0;
for(int i=amount;i>=20;i-=20)
{
counts++;
amount-=20;
}
if(counts!=0)
System.out.println("20 X "+counts);
counts=0;
for(int i=amount;i>=10;i-=10)
{
counts++;
amount-=10;
}
if(counts!=0)
System.out.println("10 X "+counts);
counts=0;
for(int i=amount;i>=5;i-=5)
{
counts++;
amount-=5;
}
System.out.println("5 X "+counts);
counts=0;
for(int i=amount;i>2=;i-=2)
{
counts++;
amount-=2;
}
if(counts!=0)
System.out.println("2 X "+counts);
counts=0;
for(int i=amount;i>=1;i-=1)
{
counts++;
amount-=1;
}
if(counts!=0)
System.out.println("1 X "+counts);
}
}
Output:-
class denomination
{
public static void main(String arg[])
{
Scanner input=new Scanner(System.in);
int amount,counts=0;
System.out.println("Enter Amount: ");
amount=input.nextInt();
for(int i=amount;i>=1000;i-=1000)
{
counts++;
amount-=1000;
}
if(counts!=0)
System.out.println("1000 X "+counts);
counts=0;
for(int i=amount;i>=500;i-=500)
{
counts++;
amount-=500;
}
if(counts!=0)
System.out.println("500 X "+counts);
counts=0;
for(int i=amount;i>=100;i-=100)
{
counts++;
amount-=100;
}
if(counts!=0)
System.out.println("100 X "+counts);
counts=0;
for(int i=amount;i>=50;i-=50)
{
counts++;
amount-=50;
}
if(counts!=0)
System.out.println("50 X "+counts);
counts=0;
for(int i=amount;i>=20;i-=20)
{
counts++;
amount-=20;
}
if(counts!=0)
System.out.println("20 X "+counts);
counts=0;
for(int i=amount;i>=10;i-=10)
{
counts++;
amount-=10;
}
if(counts!=0)
System.out.println("10 X "+counts);
counts=0;
for(int i=amount;i>=5;i-=5)
{
counts++;
amount-=5;
}
System.out.println("5 X "+counts);
counts=0;
for(int i=amount;i>2=;i-=2)
{
counts++;
amount-=2;
}
if(counts!=0)
System.out.println("2 X "+counts);
counts=0;
for(int i=amount;i>=1;i-=1)
{
counts++;
amount-=1;
}
if(counts!=0)
System.out.println("1 X "+counts);
}
}
Output:-