Advertisement
Guest User

Untitled

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