Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Task4_Walking {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int goal = 10000;
  8.         String command = scanner.nextLine();;
  9.         int steps = 0;
  10.  
  11.        int stepsWalked = 0;
  12.  
  13.         while (!command.equals("Going home")) {
  14.             steps = Integer.parseInt(command);
  15.  
  16.  
  17.             stepsWalked += steps;
  18.  
  19.             //System.out.println(stepsWalked);
  20.  
  21.             if (stepsWalked >= goal) {
  22.                 System.out.println("Goal reached! Good job!");
  23.                 return;
  24.             }
  25.             command = scanner.nextLine();
  26.  
  27.         }
  28.         if (command.equals("Going home")) {
  29.             stepsWalked += steps;
  30.             int difference = goal - stepsWalked;
  31.             System.out.printf("%d more steps to reach goal.", difference);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement