In the following code, the block under if(timesout[entry] == "exit")
will never execute. I have verified timesout[entry]
for the current loop is set as "exit" in debugging mode, as well as by printing out the variable before the if statement is evaluated, but no matter what, the block never executes when I enter exit
at the prompt, and I am stumped as to why.
import java.util.Scanner;
public class timetracker {
public static void main(String args[]) {
boolean exit = false;
String[] reasons = new String[30];
String[] timesout = new String[30];
String[] timesin = new String[30];
int entry = 0;
Scanner keyinput = new Scanner(System.in);
recordloop:
while(exit == false) {
//record info
System.out.println("Enter time out:");
timesout[entry] = keyinput.nextLine();
if(timesout[entry] == "exit") {
exit = true;
break recordloop;
}
System.out.println("Enter reason:");
reasons[entry] = keyinput.nextLine();
System.out.println("Enter time in:");
timesin[entry] = keyinput.nextLine();
entry = entry + 1;
}
System.out.println("Times away from phone:\n ----- \n");
int count = entry;
entry = entry + 1;
while(count < entry) {
System.out.println(reasons[count] + ": " + timesout[count] + " - " + timesin[count] + "\n");
count = count + 1;
}
}
}