Untitled
unknown
plain_text
2 years ago
992 B
4
Indexable
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int goalSteps = 10000; int totalSteps = 0; int stepsMade = 0; String walk = scanner.nextLine(); boolean goneHome = false; while (!goneHome) { if (walk.equals("Going home")) { goneHome = true; } stepsMade = Integer.parseInt(walk); totalSteps += stepsMade; if (totalSteps >= goalSteps) { break; } walk = scanner.nextLine(); } if (goneHome == true) { int stepsToHome = Integer.parseInt(scanner.nextLine()); totalSteps += stepsToHome; } int difference = Math.abs(totalSteps - goalSteps); if (totalSteps >= goalSteps) { System.out.printf("Goal reached! Good job!\n%d steps over the goal!", difference); } else { System.out.printf("%d more steps to reach goal.", difference); } } }
Editor is loading...