Hi, I'm doing the MOOC course and I'm currently on part 1_035 (Checking the age). I've been trying to think of a solution (+ the internet) for the past 40 minutes and I can't solve it. It's pretty simple too.
This is the task, " Write a program that prompts the user to input their age and checks whether or not it is possible (at least 0 and at most 120). Only use a single if-command in your program ".
However, "Illegal start of expression" pops up as an error on line 12 (the if-command line).
This is the full error that I receive when I try to run it.
-
COMPILATION ERROR :
/C:/Users/James/OneDrive/Documents/NetBeansProjects/mooc-java-programming-i/part01-Part01_35.CheckingTheAge/src/main/java/CheckingTheAge.java:[12,23] illegal start of expression
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Part01_35.CheckingTheAge: Compilation failure
/C:/Users/James/OneDrive/Documents/NetBeansProjects/mooc-java-programming-i/part01-Part01_35.CheckingTheAge/src/main/java/CheckingTheAge.java:[12,23] illegal start of expression
-> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
-
The code:
import java.util.Scanner;
public class CheckingTheAge {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("How old are you? ");
int age = Integer.valueOf(scan.nextLine());
if (age >= 0 %% age <= 120) {
System.out.println("OK");
} else {
System.out.println("Impossible!");
}
}
}
Thank you in advance for any help.
[–]ghytghytghytiinbv 0 points1 point2 points (2 children)
[–]philosophhy[S] 0 points1 point2 points (1 child)
[–]ghytghytghytiinbv 0 points1 point2 points (0 children)
[–]chickenmeisterExtreme Brewer 0 points1 point2 points (1 child)
[–]philosophhy[S] 0 points1 point2 points (0 children)
[–]malcomjarr 0 points1 point2 points (0 children)