-1

I can not figure out why my while loop won't break and it just keeps running I have tries making Lc 10 and I tried return but nothing will end the loop.

import java.util.Scanner;
public class BirthdayReminder
{

   public static void main (String[] args)
   {
      Scanner input = new Scanner(System.in);
      String[] BDay = new String[10];
      String[] friend = new String[10];
      int Lc = 0;
      String i;

      while(Lc < 10) {
            System.out.println("enter a friends name or zzz to quit");
            i = input.nextLine();
            if(i == "zzz") { 
                break;
            }
            else if(i != "zzz"){
            friend[Lc] = i;
            System.out.println("enter their birthday.");
            i = input.nextLine();
            BDay[Lc] = i;
            Lc++;
            return;
            }
      }
      System.out.println("hi");

   }

}

LMC
  • 10,453
  • 2
  • 27
  • 52

1 Answers1

5

You need to check string equality using equals(), not ==. Neither block of code inside the if is getting entered, so Lc is never incremented.

VeeArr
  • 6,039
  • 3
  • 24
  • 45