veronikaaa86

05. Travelling

Jun 17th, 2023
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 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 input = scanner.nextLine();
  10.         while (!input.equals("End")) {
  11.             String destination = input;
  12.             double price = Double.parseDouble(scanner.nextLine());
  13.  
  14.             double sum = 0;
  15.             while (sum < price) {
  16.                 double amount = Double.parseDouble(scanner.nextLine());
  17.  
  18.                 sum = sum + amount;
  19.             }
  20.  
  21.             System.out.printf("Going to %s!%n", destination);
  22.  
  23.             input = scanner.nextLine();
  24.         }
  25.     }
  26. }
  27.  
Add Comment
Please, Sign In to add comment