Hello all,
I've started with java code yesturday and I'm fooling around with it a little now, but...
I ran in to my first ever java problem!
I have this code down here and I want the user to either type Yes or No but I can't, the if statement is called before I even put anything.
This is probably easy to fix but since I'm completely new to java, I have no idea how to do so.
Code:
package core;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Name: ");
String name = input.nextLine();
System.out.println("Enter Age: ");
int age = input.nextInt();
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Start loop ? Type Yes or No.");
String doLoop = input.nextLine();
int loop = 0;
if (doLoop == "Yes") {
System.out.println("Loop will start.");
while (loop < 5) {
System.out.println("Looping: " + loop);
}
} else if (doLoop == "No"){
System.out.println("No loop will start, end of script.");
}
}
}