Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Travelling {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget, moneyOnHand, currentSum;
- String destination;
- while (true) {
- destination = scanner.nextLine();
- if (destination.equals("End")) {
- break;
- }
- budget = Double.parseDouble(scanner.nextLine());
- moneyOnHand = Double.parseDouble(scanner.nextLine());
- while (budget > moneyOnHand) {
- currentSum = Double.parseDouble(scanner.nextLine());
- moneyOnHand += currentSum;
- }
- System.out.printf("Going to %s!\n", destination);
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class Travelling {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String destination = "";
- while (!(destination = scanner.nextLine()).equals("End")) {
- double budget = Double.parseDouble(scanner.nextLine());
- while (budget > 0) {
- budget -= Double.parseDouble(scanner.nextLine());
- }
- System.out.printf("Going to %s!\n", destination);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement