myrdok123

05. Travelling

Jun 22nd, 2024
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. package NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Travelling_05 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         String destination = scanner.nextLine();
  11.  
  12.         //докато не получим команда "End" -> прочитаме нова дестинация
  13.         while (!destination.equals("End")){
  14.  
  15.             //Greece -> 1000
  16.             double neededMoney = Double.parseDouble(scanner.nextLine());
  17.  
  18.             double budget = 0;
  19.             //докато необходимите пари за екскурзията са по-големи от нашия бюджет -> събираме пари
  20.             while (neededMoney > budget){
  21.                 double currentMoney = Double.parseDouble(scanner.nextLine());
  22.                 budget += currentMoney;
  23.             }
  24.  
  25.             System.out.printf("Going to %s!%n", destination);
  26.  
  27.             destination = scanner.nextLine();
  28.         }
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment