Advertisement
desislava_topuzakova

05. Travelling

May 15th, 2021
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Balance_05 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String destination = scanner.nextLine(); //държава или "End"
  7.         //стоп -> destination == "End"
  8.         //продължаваме -> destination != "End"
  9.         while(!destination.equals("End")) {
  10.             //държава
  11.             double excursionPrice = Double.parseDouble(scanner.nextLine());
  12.             //събирам пари
  13.             double availableMoney = 0;
  14.             //стоп -> availableMoney >= excursionPrice
  15.             //продължава -> availableMoney < excursionPrice
  16.             while (availableMoney < excursionPrice) {
  17.                 double savedMoney = Double.parseDouble(scanner.nextLine());
  18.                 availableMoney += savedMoney;
  19.             }
  20.             //налични пари > пари за екскурзията
  21.             System.out.printf("Going to %s!%n", destination);
  22.             destination = scanner.nextLine();
  23.         }
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement