Hello I am having a some difficulty with a very simple program.
import java.util.*;
public class Compare
{
public static void main( String args[] )
{
String username;
Scanner input = new Scanner(System.in);
String users[] = {"John", "James", "Smith", "Paul"};
System.out.println("Please Enter Username: ");
username = input.next();
for( int i = 0; i < users.length(); i ++ )
{
if( users[i] == username )
System.out.println("Match");
else
System.out.println("No Match");
}
}
}
When I run this program I get No Match which I don't know how is possible when I enter the same string as on of the strings in the users array. Any Suggestions?