Sunday, January 26, 2014

To display amount into 500’S,100’S,50’S,20’S,10’S,5’S,2’S,1’S in a given number

Write a program to display amount into 500’S,100’S,50’S,20’S,10’S,5’S,2’S,1’S in a given number


import java.util.Scanner;

public class AmountCount

{

      public static void main(String[] args)

{

              System.out.println("Enter the amount in rupees:-");

              Scanner sc=new Scanner(System.in);

              int num=sc.nextInt();

              while(num>=500)

              {

                        int a=num/500;

                        System.out.print("\n The no .of five hundreds are:- "+ a);

                        break;

              }

              while(num>=100){

                          int a=num/100;

                        System.out.print("\n The no .of hundreds are :-"+ a);

                        break;

              }

              while(num>=50){

                        int a=num/50;

                        System.out.print("\n The no .of fiftie's are "+ a);

                        break; 

              }

              while(num>=20)

              {

                        int a=num/20;

                        System.out.print("\n The no .of twenty's are "+ a);

                        break;

              }

              while(num>=10){

                        int a=num/10;

                        System.out.print("\n The no .of ten's are "+ a);

                        break;

              }

              while(num>=5){

                        int a=num/5;

                        System.out.print("\n The no .of five's are "+ a);

                        break; 

              }

              while(num>=2){

                        int a=num/2;

                        System.out.print("\n The no .of two's are "+ a);

                        break;

           



  }

              while(num>=1)

              {

                        int a=num/1;

                        System.out.print("\n The no.of one's are"+ a);

                        break;

              }

              }

            }



OUTPUT:



Enter the amount in rupees:-

1854



The no .of five hundreds are 3

The no .of hundreds are 18

The no .of fiftie's are 37

The no .of twenty's are 92

The no .of ten's are 185

The no .of five's are 370

The no .of two's are 927

The no.of one's are1854





No comments:

Post a Comment