I am having trouble with understanding what is wrong with this code. On Dr.Java everything is working fine but on another code running platform called edhesive (which is where i was assigned this project) it is giving me an error. I have checked everything that i could think is going wrong but still don't know what is wrong.
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Welcome. What is your name?");
String name = scan.next();
System.out.println("Hello " + name + ". Try your best to crack the code!");
System.out.println("PHASE 1");
System.out.println("Enter a number:");
int phaseOneNum = scan.nextInt();
if (phaseOneNum == 3)
{
System.out.println("Correct!");
System.out.println("PHASE 2");
System.out.println("Enter a number:");
int phaseTwoNum = scan.nextInt();
if (phaseTwoNum == 1 || (phaseTwoNum > 33 && phaseTwoNum<= 100))
{
System.out.println("Correct!");
System.out.println("PHASE 3");
System.out.println("Enter a number:");
int phaseThreeNum = scan.nextInt();
if (phaseThreeNum > 0 && ((phaseThreeNum % 3 == 0) || (phaseThreeNum % 7 == 0)))
{
System.out.println("Correct!");
System.out.println("You have cracked the code!");
}
else
{
System.out.println("Sorry, that was incorrect!");
System.out.println("Better luck next time!");
}
}
else
{
System.out.println("Sorry, that was incorrect!");
System.out.println("Better luck next time!");
}
}
else
{
System.out.println("Sorry, that was incorrect!");
System.out.println("Better luck next time!");
}
}
}
After running it on edhesive, I get this error
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:184)
at Ideone.test(Main.java:111)
at Ideone.test(Main.java:31)
at Ideone.main(Main.java:23)
Can someone help me please?