Advertisement
Zneeky

Zad6/ Travelling

Oct 21st, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package VlojeniCikli;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Zad6 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String destination=scanner.nextLine();
  10.         int budgetNeeded=Integer.parseInt(scanner.nextLine());
  11.         int sum=0;
  12.  
  13.         while (!destination.equals("End")){
  14.  
  15.             int money=Integer.parseInt(scanner.nextLine());
  16.             sum+=money;
  17.  
  18.             if (sum==budgetNeeded||sum>budgetNeeded){
  19.                 System.out.printf("Going to %s!\n",destination);
  20.                 sum=0;
  21.                 destination=scanner.nextLine();
  22.                 if ("End".equals(destination)){
  23.                     break;
  24.                 }
  25.                 budgetNeeded=Integer.parseInt(scanner.nextLine());
  26.             }
  27.  
  28.         }
  29.  
  30.  
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement