Hi
I want to write a program that keeps track of how many times a bus is late.
So the user is asked to enter an int value, indicating how many minutes late.
Once a negative int is entered, the program should stop.
What I’m having trouble with is making the program repeat only for inputs of 0 or more.
The program repeats regardless of what int is inputted.
I did something like below:
import java.util.Scanner;
public class LateBus {
public static void main(String[] args) {
int enter_minutes = enterMinutes();
loop(enter_minutes);
}
public static int enterMinutes() {
Scanner enter = new Scanner(System.in);
System.out.print("How many minutes late was the bus? ");
int late = enter.nextInt();
return late;
}
public static void loop(int a) {
while (a >= 0) {
enterMinutes();
}
}
}