Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kolosaisd;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- public class Wydawanie_reszty_BS {
- public static void main(String[] args){
- 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};
- double reszta=0;
- Scanner sc = new Scanner(System.in);
- System.out.print("Wczytaj resztę do wypłacenia: ");
- try {
- reszta = sc.nextDouble();
- }
- catch (InputMismatchException ex) {
- System.out.println("Nieprawidłowa wartość!");
- }
- String wynik = "Reszta: \n";
- for(int i = 0;((i < NOMINALY.length) && (reszta > 0.00));i++){
- if (reszta >= NOMINALY[i]) {
- int temp = (int)Math.floor(reszta/NOMINALY[i]);
- wynik += "Nominał: "+ NOMINALY[i] + " PLN wypłacono: " + temp + " szt. \n";
- reszta = (double) Math.round(100*(reszta-(temp*NOMINALY[i])))/100;
- }
- }
- System.out.println(wynik);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement