Issue
I'm attempting to submit my code for automatic review and I'm getting failures that I don't quite understand. I am using Netbeans with TMC for submission in MOOC.fi. The two errors I am getting specifically are:
This is the code in question:
import java.util.Scanner;
public class CheckYourIndentation {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Give a number: ");
int first = Integer.valueOf(scan.nextLine());
System.out.println("Give another number: ");
int second = Integer.valueOf(scan.nextLine());
if (first == second) {
System.out.println("Same!");
}
else if (first > second) {
System.out.println("The first was larger than the second!");
}
else {
System.out.println("The second was larger than the first!");
}
}
}
Here is the code in Pastebin.
Solution
I needed to put else if
and else
on the same line as the final brackets of the previous block. In other words, this was the correct final result: https://pastebin.com/CchVXq2M
if (first == second) {
System.out.println("Same!");
} else if (first > second) {
System.out.println("The first was larger than the second!");
} else {
System.out.println("The second was larger than the first!");
}
Answered By - EightFiveZeroEight
Answer Checked By - Katrina (JavaFixing Volunteer)