desislava_topuzakova

05. Travelling

Mar 14th, 2021
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class demo2 {
  5.     public static void main(String[] args){
  6.         Scanner scanner = new Scanner(System.in);
  7.         //команда -> дестинация или end
  8.         String command = scanner.nextLine();
  9.         //спираме: command == "end"
  10.         //продължаваме: command != "end"
  11.  
  12.         while(!command.equals("End")) {
  13.             //дестинация
  14.             double budget = Double.parseDouble(scanner.nextLine());
  15.             double money = 0;
  16.             //спестява
  17.             //спира: парите >= бюджета
  18.             //продължава: парите < бюджета
  19.             while (money < budget) {
  20.                 double savedMoney = Double.parseDouble(scanner.nextLine());
  21.                 money += savedMoney;
  22.             }
  23.  
  24.             System.out.println("Going to " + command + "!");
  25.  
  26.             command = scanner.nextLine();
  27.         }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment