Write a java program to count total number of notes in entered amount using loop


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.io.*;
  2.  
  3. class Javaexcercise
  4. {
  5. public static void main(String args[])throws IOException
  6. {
  7. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  8.  
  9. int Rs[]={1000,500,100,50,20,10,5,2,1};
  10.  
  11. System.out.print("Enter any Amount : ");
  12. int amount=Integer.parseInt(br.readLine());
  13.  
  14. int copy=amount;
  15. int totalNotes=0,count=0;
  16.  
  17. System.out.println("\nRs OMINATIONS : \n");
  18.  
  19. for(int i=0;i<9;i++)
  20. {
  21. // counting number of notes.
  22. count=amount/Rs[i];
  23. if(count!=0)
  24. {
  25. System.out.println(Rs[i]+"\tx\t"+count+"\t= "+Rs[i]*count);
  26. }
  27. totalNotes=totalNotes+count;
  28. amount=amount%Rs[i];
  29. }
  30.  
  31. System.out.println("--------------------------------");
  32.  
  33. // printing the total amount
  34. System.out.println("TOTAL\t\t\t= "+copy);
  35. System.out.println("--------------------------------");
  36.  
  37. // printing the total number of notes
  38. System.out.println("Total Number of Notes\t= "+totalNotes);
  39. }
  40. }

Result

java techstudy.org

     





Related Topics




Popular Posts