I am working on a project in Java and I have written an if statement in order to call different constructors depending on what the user inputs (whether they want to load the default file or choose their own file path). However it seems to only be going to the else statement not the if statement. I tried to put continue after calling the constructor but I get an error.
import java.io.File;
import java.util.Scanner;
public class ShortenerUtility {
public static void main(String[] args)
{
System.out.println("Would you like to open the default file?");
Scanner sc1 = new Scanner(System.in);
String input1;
input1 = sc1.nextLine().toLowerCase();
System.out.println(input1);
if (input1 == "yes")
{
Shortener s1 = new Shortener();
}
else
{
System.out.println("Please Enter the file path");
Scanner sc2 = new Scanner(System.in);
String input2;
input2 = sc1.nextLine();
Shortener s2 = new Shortener(input2);
}
}
}
This returns the following:
Would you like to open the default file?
Yes
yes
Please Enter the file path
When I put the continue after the Shortener I get this:
Shortener s1 = new Shortener();
continue;
With this error message:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
continue cannot be used outside of a loop
at ShortenerUtility.main(ShortenerUtility.java:20)