whenever i try to do a loop in java, it does this wierd thing where it repeats the printed lines multiple times. this is a problem for me because everytime my instructor asks us to make a program that uses a loop(most every program we make now) he sees this and says it's a probem. i asked him how to fix it but he either doesnt know or expects us to figure it out on our own(everybody else is having the same problem). here's an example:
will output this if you enter the wrong passwordCode:import java.io.*;
class password {
public static void main (String args[])
throws java.io.IOException {
char input, passwd='y';
do {
System.out.print("Enter your password: ");
input=(char)System.in.read();
if(input!=passwd) System.out.print("wrong password");
}
while(input!=passwd);
System.out.println("you got it");
}
}
and then the user can input another letterQuote:
wrong passwordEnter your password: wrong passwordEnter your password: wrong passwordEnter your password:
what it should do is just say "wrong password" and then wait for input again... anybody know what the problem is?
