Reputation:
I am a newbie to Java programming and I'm working on this self project. I'm wondering how do i loop a user's input then write to a file, but upon entering a text test to see if the input is correct. So here is where I get confused.
System.out.println(" enter what you want to teach me"); // data
while (!Keyboard.hasNext()) {
String lines = Keyboard.nextLine();
System.out.print(" is this correct ? ");
System.out.println("\n");
String go = input.nextLine();
if ( go == "yes"){
wr.write(lines);
wr.write("\n"); }
wr.newLine();
wr.close();
}
The loop is never reached and I'm lost to why this is happening.
Upvotes: 2
Views: 122
Reputation: 66
A couple pointers:
if (go.equals("yes")) { ... }
Upvotes: 1
Reputation: 933
Try removing the !
in your while
statement. If I'm understanding this correctly you want the loop to run until Keyboard has been iterated through. With the !
being there the loops condition is never true.
Upvotes: 2
Reputation: 1
debug it and you will find your answer. If someone gives you a correct code now, you will be stuck like forever in this loop.
Upvotes: 0