首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么我的while循环不会中断

为什么我的while循环不会中断
EN

Stack Overflow用户
提问于 2018-06-02 07:08:46
回答 1查看 108关注 0票数 -1

我不明白为什么我的while循环不会中断,它一直在运行,我试着做LC10,我试着返回,但是没有什么能结束这个循环。

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");

   }

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-02 07:15:48

您需要使用equals()而不是==来检查字符串相等性。if中的两个代码块都不会被输入,因此Lc永远不会递增。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50651990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档