Advertisement
KolosAISD

ResztaBS

Nov 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1.  
  2. package kolosaisd;
  3.  
  4. import java.util.InputMismatchException;
  5. import java.util.Scanner;
  6.  
  7. public class Wydawanie_reszty_BS {
  8.  
  9. public static void main(String[] args){
  10. final double[] NOMINALY = {200.0,100.0,50.0,20.0,10.0,5.0,2.0,1.0,0.5,0.2,0.1,0.05,0.02,0.01};
  11. double reszta=0;
  12.  
  13. Scanner sc = new Scanner(System.in);
  14. System.out.print("Wczytaj resztę do wypłacenia: ");
  15.  
  16. try {
  17. reszta = sc.nextDouble();
  18. }
  19. catch (InputMismatchException ex) {
  20. System.out.println("Nieprawidłowa wartość!");
  21. }
  22.  
  23. String wynik = "Reszta: \n";
  24.  
  25. for(int i = 0;((i < NOMINALY.length) && (reszta > 0.00));i++){
  26. if (reszta >= NOMINALY[i]) {
  27. int temp = (int)Math.floor(reszta/NOMINALY[i]);
  28. wynik += "Nominał: "+ NOMINALY[i] + " PLN wypłacono: " + temp + " szt. \n";
  29. reszta = (double) Math.round(100*(reszta-(temp*NOMINALY[i])))/100;
  30. }
  31.  
  32. }
  33. System.out.println(wynik);
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement