Sunday, March 8, 2020

Java Program On Denomination Of An Input Amount




Example 1:
INPUT: 14836
OUTPUT: ONE FOUR EIGHT THREE SIX
DENOMINATION:
1000 X 14 =14000
500   X 1 =500
100   X 3 =300
50     X 1 =50
5      X 1 =5
1    X 1 =1


EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT


import java.io.*;
class Bank
{
int rev=0,amount,dummy;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void intake() throws IOException
{
System.out.println("Enter the Amount:");
amount=Integer.parseInt(br.readLine());
if(amount >99999)
{
System.out.println("Invalid Amount...");
return;
}
dummy=amount;
while(dummy >0)
{
rev=rev*10+dummy%10;
dummy=dummy/10;
}
System.out.print("Amount in words :");
while(rev >0)
{
switch(rev%10)
{
case 0:
System.out.print(" ZERO");
break;
case 1:
System.out.print(" ONE");
break;
case 2:
System.out.print(" TWO");
break;
case 3:
System.out.print(" THREE");
break;
case 4:
System.out.print(" FOUR");
break;
case 5:
System.out.print(" FIVE");
break;
case 6:
System.out.print(" SIX");
break;
case 7:
System.out.print(" SEVEN");
break;
case 8:
System.out.print(" EIGHT");
break;
case 9:
System.out.print(" NINE");
break;
}
rev=rev/10;
}
System.out.println("\nDENOMINATORS:\n");
rev=amount/1000;
if(rev!=0)

System.out.println("1000 X " + rev + " = " + rev*1000);

amount=amount%1000;
rev=amount/500;
if(rev!=0)
System.out.println("500 X " + rev + " = " + rev*500);
amount=amount%500;
rev=amount/100;
if(rev!=0)
System.out.println("100 X " + rev + " = " + rev*100);
amount=amount%100;
rev=amount/50;
if(rev!=0)
System.out.println("50 X " + rev + " = " + rev*50);
amount=amount%50;
rev=amount/20;
if(rev!=0)
System.out.println("20 X " + rev + " = " + rev*20);
amount=amount%20;
rev=amount/10;
if(rev!=0)
System.out.println("10 X " + rev + " = " + rev*10);
amount=amount%10;
rev=amount/5;
if(rev!=0)
System.out.println("5 X " + rev + " = " + rev*5);
amount=amount%5;
rev=amount/2;
if(rev!=0)
System.out.println("2 X " + rev + " = " + rev*2);
amount=amount%2;
rev=amount/1;
if(rev!=0)
System.out.println("1 X " + rev + " = " + rev*1);
}
}


Back To 2010 Computer Practical Paper: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner