Advertisement
veronikaaa86

05. Travelling

Oct 15th, 2022
1,176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. package nestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05Travelling {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String inputLine = scanner.nextLine();
  10.         while (!inputLine.equals("End")) {
  11.             String destination = inputLine;
  12.             double priceTrip = Double.parseDouble(scanner.nextLine());
  13.  
  14.             double sum = 0;
  15.             while (sum < priceTrip) {
  16.                 double amount = Double.parseDouble(scanner.nextLine());
  17.                 sum = sum + amount;
  18.             }
  19.  
  20.             System.out.printf("Going to %s!%n", destination);
  21.  
  22.             inputLine = scanner.nextLine();
  23.         }
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement