import java.util.*; // I have created a simple Interviewer where it asks for name and age and ask if it is correct with a yes/no function. // I have compiled and ran this in Eclipse IDE, i have not encountered any critical errors but i have with yellow warnings. // I'm struggling with using the Scanner utility. // Apologises with structure, new to this. public class scanner { public static void main(String[] args) { Scanner userInput = new Scanner(System.in); // Yellow warning, is this right? Says 'convert local variable to field'* String version = "v1"; String wlcmsg; wlcmsg = "Welcome to Interviwer " + version + "."; System.out.print(wlcmsg); // Welcome message. System.out.println(" Please press 'enter' to continue..."); try { System.in.read(); } catch (Exception e) { //Works fine, Press the 'enter' key and takes me to next step. } for(int clear = 0; clear <= 50; clear++) { System.out.println(" "); // Prints 50 Lines of spaces, Using this as clearing screen but not sure if this is recommended. Any easier way or other code to do the same concept? ** } System.out.println("\n"); String blank = userInput.nextLine(); // I AM NOT SURE I NEED THIS? When i remove line 27 & 28, userInput does not work for line 29/30. System.out.println(blank + "Please enter your name: "); String name = userInput.nextLine(); for(int clear = 0; clear <= 50; clear++) { System.out.println(" ") ; //** } System.out.print("Hello " + name + ", I am your personal interviewer " + version + "\n" + "So, How old are you?"); int age = userInput.nextInt(); for(int clear = 0; clear <= 50; clear++) { System.out.println(" ") ; //** } System.out.println("So your name is " + name + " and you are " + age + " years old." + "\n" + "Is this correct?"); Scanner options = new Scanner(System.in); //* if(options.next().equalsIgnoreCase("y")||options.next().equalsIgnoreCase("options")) { // The yes option seems to work but no and the invalid characters does not seem to print out. Have i went wrong here? System.out.println("This will be fun"); } else if(options.next().equalsIgnoreCase("n")||options.next().equalsIgnoreCase("no")) { System.out.println("Maybe next time"); } else { System.out.println("Invalid character"); } } }
options.next()
"n"
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)