Skip to main content

CURRENCY DENOMINATION

PROGRAM: CURRENCY DENOMINATION

The Objective is to get currency in sorted manner ie.
if user have 5412 Rs
then the output might be

2 X 2000 = 4000
1 X 1000 = 1000
4 X 100  = 400
1 X 10   = 10
1 X 2    = 2
__________________
TOTAL:  5412

SYNTAX

import java.io.*;
class currency_denom
{
static int a[]={2000,1000,500,100,50,20,10,5,2};static int x=0;
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter Amount");
        int n=Integer.parseInt(br.readLine());System.out.println("DENOMINATED CURRENCY:");
        int tot=n;
        den(n,a[x]);
        System.out.println("____________________\nTOTAL: "+tot);
    }

    public static void den(int n,int cur)
    {
        if(n>=2000)
        {int c=n/2000;
            System.out.println(c+" X 2000 = "+(c*2000));
            n=n%2000;
            if(n!=0)
                den(n,a[x++]);
        }
        else  if(n>=1000)
        {
            int c=n/1000;
            System.out.println(c+" X 1000 = "+(c*1000));
            n=n%1000;
            if(n!=0)
                den(n,a[x++]);
        }
        else
        if(n>=500)
        {
            int c=n/500;
            System.out.println(c+" X 500  = "+(c*500));
            n=n%500;
            if(n!=0)den(n,a[x++]);
        }
        else
        if(n>=100)
        {
            int c=n/100;
            System.out.println(c+" X 100  = "+(c*100));
            n=n%100;
            if(n!=0)den(n,a[x++]);
        }
        else
        if(n>=50)
        {
            int c=n/50;
            System.out.println(c+" X 50   = "+(c*50));
            n=n%50;
            if(n!=0)den(n,a[x++]);
        }
        else if(n>=20)
        {int c=n/20;
            System.out.println(c+" X 20   = "+(c*20));
            n=n%20;
            if(n!=0)den(n,a[x++]);
        }
        else if(n>=10){
            int c=n/10;
            System.out.println(c+" X 10   = "+(c*10));
            n=n%10;
            if(n!=0)den(n,a[x++]);
        }
        else if(n>=5){
            int c=n/5;
            System.out.println(c+" X 5    = "+(c*5));
            n=n%5;
            if(n!=0)den(n,a[x++]);
        }
        else if(n>=2){
            int c=n/2;
            System.out.println(c+" X 2    = "+(c*2));
            n=n%2;
            den(n,a[x]);}

        else if(n>=1)System.out.println(n+" X 1    = "+n);
    }
}

SCREEN SHOTS

Comments

Popular posts from this blog

Arranging according to potential.

PROGRAM: Requested by Sir  Ankur Acharya   ARRANGING WORDS IN A STRING ACCORDING TO THEIR POTENTIAL The encryption of alphabets are to be done as follows: A = 1 B = 2 C = 3 . . . Z = 26 The potential of a word is found by adding the encrypted value of the alphabets. Example: KITE Potential = 11 + 9 + 20 + 5 = 45 Accept a sentence which is terminated by either “ . ” , “ ? ” or “ ! ”. Each word of sentence is separated by single space. Decode the words according to their potential and arrange them in ascending order. Output the result in format given below: Example 1 INPUT : THE SKY IS THE LIMIT. POTENTIAL : THE = 33 SKY = 55 IS = 28 THE = 33 LIMIT = 63 OUTPUT : IS THE THE SKY LIMIT Example 2 INPUT : LOOK BEFORE YOU LEAP. POTENTIAL : LOOK = 53 BEFORE = 51 YOU = 61 LEAP = 34 OUTPUT : LEAP BEFORE LOOK YOU SYNTAX import java.io.*; class Potential {     public static void main(String args[])throws IOException     {       ...

Disarium Number

AJ Java Programs Program 4: Disarium Number A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number. For example  135 is a DISARIUM (Workings 1 1 +3 2 +5 3  = 135, some other  DISARIUM  are 89, 175, 518 etc) Syntax: import java.io.*; class disarium {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,n1,n2,c=0,sum=0,d=0;         System.out.println("Enter a Num");         n=Integer.parseInt(br.readLine());         n2=n1=n;         while(n2!=0)         {             n2=n2/10;             c++;         }       ...

MAGICAL/ MAGIC NUMBER USING RECURSION

PROGRAM :  MAGICAL NUMBER BY RECURSION This  program  checks if a  number  is a  Magic number  in  JAVA . A  number  is said to be a  Magic number  if the sum of its digits are calculated till a single digit is obtained by recursively adding the sum of its digits. If the single digit comes to be 1 then the  number  is a  magic number . Example: 10999 => 1+0+9+9+9=28=>2+8=>10=>1+0= 1                  199    =>1+9+9 =>19=> 1+9=>10=>1+0= 1 SYNTAX import java.io.*; class magic  {    static int c;     public static void main(String arsg[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int d=0;int m;         System.out.println("ENter a NUmber");   ...