Advertisement
Spocoman

05. Travelling

Aug 30th, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Travelling {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double budget, moneyOnHand, currentSum;
  7.         String destination;
  8.  
  9.         while (true) {
  10.             destination = scanner.nextLine();
  11.             if (destination.equals("End")) {
  12.                 break;
  13.             }
  14.  
  15.             budget = Double.parseDouble(scanner.nextLine());
  16.             moneyOnHand = Double.parseDouble(scanner.nextLine());
  17.  
  18.             while (budget > moneyOnHand) {
  19.                 currentSum = Double.parseDouble(scanner.nextLine());
  20.                 moneyOnHand += currentSum;
  21.             }
  22.  
  23.             System.out.printf("Going to %s!\n", destination);
  24.         }
  25.     }
  26. }
  27.  
  28. ИЛИ:
  29.  
  30. import java.util.Scanner;
  31.  
  32. public class Travelling {
  33.     public static void main(String[] args) {
  34.         Scanner scanner = new Scanner(System.in);
  35.         String destination = "";
  36.  
  37.         while (!(destination = scanner.nextLine()).equals("End")) {
  38.             double budget = Double.parseDouble(scanner.nextLine());
  39.             while (budget > 0) {
  40.                 budget -= Double.parseDouble(scanner.nextLine());
  41.             }
  42.             System.out.printf("Going to %s!\n", destination);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement