0
import java.util.Scanner;

public class LoginPage{

public static void main (String[]args){

System.out.println("______________");
System.out.println("| Login Page |");
System.out.println("______________");

System.out.println();

//Declare Strings
String Log;
String Pass;
String TestU = "Corey";
String TestP = "Chicken";
int i = 0;
//Declare Scanner
Scanner scan = new Scanner (System.in);

while(i<=6){
    System.out.print("Username: ");
    Log = scan.nextLine();
    System.out.print("Password: ");
    Pass = scan.nextLine();
    i++;

    if((Log==TestU)&&(Pass==TestP))
    {break;}

}

}

}

This is the current code for a login page i'm trying to create. The 'TestU' and 'TestP' are just there instead of usernames/password that i will read from a data file. But when i enter in 'Corey' and 'Chicken' it doesn't exit the while loop. I might just be doing something very simple wrong but i cannot find it and i cannot find it on google or anything(Maybe i'm searching the wrong problem.) But any help would be greatly appreciated.

SpringLearner
  • 13,738
  • 20
  • 78
  • 116
  • 4
    See [How to Compare Strings in Java](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java). Use `String.equals` not `==`. – Arc676 Nov 19 '15 at 12:35
  • replace `if((Log==TestU)&&(Pass==TestP))` with `if((Log.equals(TestU))&&(Pass.equals(TestP)))` – SpringLearner Nov 19 '15 at 12:36

1 Answers1

0

You have to compare the string with with String.equals

Si mo
  • 969
  • 9
  • 24