yovkovbpfps

While Loop Walking

Apr 3rd, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exercise1002 {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int totalSteps = 0;
  9.  
  10. while (totalSteps < 10000) {
  11. String input = scanner.nextLine();
  12.  
  13. if ( input.equals("Going home")){
  14. int bonusSteps = Integer.parseInt(scanner.nextLine());
  15. totalSteps += bonusSteps;
  16. break;
  17. }
  18.  
  19. int steps = Integer.parseInt(input);
  20. totalSteps += steps;
  21. }
  22. if (totalSteps >= 10000){
  23. System.out.println("Goal reached! Good job!");
  24. }else{
  25. System.out.printf("%d more steps to reach goal.",10000 - totalSteps);
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment