I'm trying to make a program that counts the number of steps someone made (the program should stop if the number is bigger or equal to 10000), but I can't seem to find a way to type "Going home" and then input the amount of steps that are necessary to get home.
Scanner scan = new Scanner(System.in);
int totalSteps = 0;
while(true)
{
int steps = scan.nextInt();
totalSteps = totalSteps + steps;
if(totalSteps >= 10000) {
System.out.println("Goal reached! Good job!");
break;
}
else if(steps < 10000)
{
String home = scan.nextLine();
if(home.equals("Going home"))
{
int extraSteps = scan.nextInt();
totalSteps = totalSteps + steps + extraSteps;
System.out.println(10000 - totalSteps + " more to reach goal.");
}
}
}