I am learning java at the moment and I was trying to make a simple program that recieves a username and gives you an opurtunity to change that username...However,the program is always doing the same thing: It doesn't give me a chance to change my username.I am sure that the problem is in the function I made:
public String change (String Accname) {
String chg;
System.out.println("Are you satisfied with this username: "+Accname+"?");
chg=in.nextLine();
if(chg=="yes"||chg=="Yes") {
return Accname;
} else if(chg=="no"||chg=="No") {
System.out.println("What would you want your username to be?");
Accname=in.nextLine();
}
return Accname;
}
I wrote this line at the main function:
name.change(username);
(of course,it's not the full code,I gave you the important line). After this line my program gives me the username without an opurtunity to change my username.It's like the program ignores the change function. This problem also happend a while ago in c while i was trying to make a simple program that switches between two numbers.At the end,nothing happens.
If someone could help me,I would really appreciate it!