Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ls223iu_assign1;
- import java.util.Scanner;
- public class Vaxel {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Ange varans pris, och sedel du betalar med.");
- System.out.print("Pris: ");
- float price = sc.nextFloat();
- System.out.print("Betalning: ");
- int customerPayment = sc.nextInt();
- int change = Math.round(customerPayment - price);
- System.out.println("Växel: " + change);
- int thousand = 0;
- int fivehundred = 0;
- int twohundred = 0;
- int onehundred = 0;
- int fifty = 0;
- int twenty = 0;
- int ten = 0;
- int five = 0;
- int two = 0;
- int one = 0;
- if (change >= 1000) {
- change -= 1000;
- thousand++;
- }
- if (change >= 500) {
- change -= 500;
- fivehundred++;
- }
- if (change >= 200) {
- change -= 200;
- twohundred++;
- }
- if (change >= 100) {
- change -= 100;
- onehundred++;
- }
- if (change >= 50) {
- change -= 50;
- fifty++;
- }
- if (change >= 20) {
- change -= 20;
- twenty++;
- }
- if (change >= 10) {
- change -= 10;
- ten++;
- }
- if (change >= 5) {
- change -= 5;
- five++;
- }
- if (change >= 2) {
- change -= 2;
- two++;
- }
- if (change >= 1) {
- change -= 1;
- one++;
- }
- // Andra "loopen"
- if (change >= 1000) {
- change -= 1000;
- thousand++;
- }
- if (change >= 500) {
- change -= 500;
- fivehundred++;
- }
- if (change >= 200) {
- change -= 200;
- twohundred++;
- }
- if (change >= 100) {
- change -= 100;
- onehundred++;
- }
- if (change >= 50) {
- change -= 50;
- fifty++;
- }
- if (change >= 20) {
- change -= 20;
- twenty++;
- }
- if (change >= 10) {
- change -= 10;
- ten++;
- }
- if (change >= 5) {
- change -= 5;
- five++;
- }
- if (change >= 2) {
- change -= 2;
- two++;
- }
- if (change >= 1) {
- change -= 1;
- one++;
- }
- // Tredje loopen
- if (change >= 1000) {
- change -= 1000;
- thousand++;
- }
- if (change >= 500) {
- change -= 500;
- fivehundred++;
- }
- if (change >= 200) {
- change -= 200;
- twohundred++;
- }
- if (change >= 100) {
- change -= 100;
- onehundred++;
- }
- if (change >= 50) {
- change -= 50;
- fifty++;
- }
- if (change >= 20) {
- change -= 20;
- twenty++;
- }
- if (change >= 10) {
- change -= 10;
- ten++;
- }
- if (change >= 5) {
- change -= 5;
- five++;
- }
- if (change >= 2) {
- change -= 2;
- two++;
- }
- if (change >= 1) {
- change -= 1;
- one++;
- }
- // Skriv ut resultat
- System.out.println("1000 kr-sedlar: " + thousand);
- System.out.println("500 kr-sedlar: " + fivehundred);
- System.out.println("200 kr-sedlar: " + twohundred);
- System.out.println("100 kr-sedlar: " + onehundred);
- System.out.println("50 kr-sedlar: " + fifty);
- System.out.println("20 kr-sedlar: " + twenty);
- System.out.println("10 kr-sedlar: " + ten);
- System.out.println("5 kr-sedlar: " + five);
- System.out.println("2 kr-sedlar: " + two);
- System.out.println("1 kr-sedlar: " + one);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement