You declare static void userInput()
as taking no parameters, but you attempt to pass in 1 parameter: userInput(input2check)
. You should also make userInput
static boolean userInput()
, because you are looking for a true/false statement as to whether the loop should break. Therefore, in your second for loop, you would have an if statement referring to userInput()
:
public class time9 {
static boolean userInput() {
Scanner input = new Scanner(System.in);
String input2check = input.next();
return (input2check != null);
/*true/false statement: return whether input2check is not null. Return true if not null, false otherwise.*/
}
static void timeUnit() {
for(int i = 1; i<60; i++) {
**//this makes seconds, minutes and hours**
}
}
public static void main(String[] args) {
for (int i = 1; i<60; i++){
if (userInput()){break;}
else{timeUnit);
}
}
}
You again tried to pass parameter i
into static void timeUnit()
which takes no parameters. Don't do it. Either declare a method like
[accessModifier] [returnType] [methodName] (parameter(s))
,
and call it as [methodName](parameters)
or declare it as [accessModifier] [returnType] [methodName]()
, and call it as [methodName]()
.
If you pass params into a method that takes none, it has no algorithm to deal with those params and will not compile. If you pass no params into a method that takes params, it will not have an algorithm to deal with the lack of params, and will not compile.
Lastly, please know that your time loop should have nothing to do with the number 60 except by coincidence. Iterating 60 times through a for loop will NOT take 60 seconds. For loops can iterate several hundreds of thousands of times per second, so your 60 iteration for loop would take a matter of nanoseconds, unless you are using something like Thread.sleep(millis, nanos)
which pauses the process for the milliseconds and nanos you set it to.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…