使用while循环检查和验证Java数组

使用while循环检查和验证Java数组,java,arrays,while-loop,contains,joptionpane,Java,Arrays,While Loop,Contains,Joptionpane,我需要一些代码方面的帮助。 我需要 制作一个节目,询问你将要谈论的话题,然后谈论它们。 程序应检查数组中的“?”并说出不允许的问题 检查他们输入的主题,并要求他们“讲述更多信息” “x” 如果在选项中按了“取消”或包含“再见”,则结束。 这是到目前为止我的代码 import java.util.*; import javax.swing.*; public class ATSEStage2 { public static void main(String[] args) {

我需要一些代码方面的帮助。 我需要

  • 制作一个节目,询问你将要谈论的话题,然后谈论它们。
  • 程序应检查数组中的“?”并说出不允许的问题

  • 检查他们输入的主题,并要求他们“讲述更多信息” “x”

  • 如果在选项中按了“取消”或包含“再见”,则结束。

这是到目前为止我的代码

import java.util.*;
import javax.swing.*;

public class ATSEStage2 {


public static void main(String[] args) {


    String tmma = "Tell me more about ";

    JOptionPane.showMessageDialog(null, "Hi, Welcome to ATSE \nStarting Input taking Phase...");



    int N = Integer.parseInt(JOptionPane.showInputDialog("How many Topics will you be talking about?"));
    double [] topics;
    topics = new double [N];
    String [] kw = new String[N];
    String [] chat = new String [N];

    int i=0; int a=1;
    while(i<N) {
    kw [i] = JOptionPane.showInputDialog("Enter Topic "+a);
    System.out.println(kw [i]);
    i++;
    a++;
    }
    i=0;a=0;

    String formattedString = Arrays.toString(kw)
            .replace("[", "")  
            .replace("]", ""); 

    JOptionPane.showMessageDialog(null,
            "The Topics you entered were, " +formattedString + "\nStarting Chatting phase...");

    int e=0;
    List<String> list = Arrays.asList(kw);


        chat [e] = JOptionPane.showInputDialog(null, tmma + formattedString);

        List<String> list1 = Arrays.asList(chat);
        while(e==0) {

            If (list1.contains("?"));{chat [e] = JOptionPane.showInputDialog(null, tmma + formattedString);
        e++;
        }
        }
    }
import java.util.*;
导入javax.swing.*;
第二阶段公开课{
公共静态void main(字符串[]args){
String tmma=“告诉我更多关于”;
showMessageDialog(null,“您好,欢迎来到ATSE\n启动输入获取阶段…”);
int N=Integer.parseInt(JOptionPane.showInputDialog(“您将谈论多少主题?”);
双[]主题;
主题=新双[N];
字符串[]千瓦=新字符串[N];
字符串[]聊天=新字符串[N];
int i=0;int a=1;

当(i@Lonath Senevirathne时,您使用的是
List
类的
contains()
方法。如果打开它,您会看到它的描述说
如果此列表包含指定的元素,则返回true。更正式地说,如果且仅当此列表包含至少一个元素e,则返回true(o==null?e==null:o.equals(e))。
。如果希望能够检查/验证数组中的单词,并在其中包含特定单词时循环它,则应遍历所有列表元素

while (e == 0) {

    for (String st : list1) {
        if (st != null && st.contains("?")) {
            chat[e] = JOptionPane.showInputDialog(null, tmma + formattedString);
            e++;
        }
    }
}
使用
while循环

int idx = 0;
while(idx < list1.size()) {
   if (list1.get(idx) != null && list1.get(idx).contains("?")) {
        chat[e] = JOptionPane.showInputDialog(null, tmma + formattedString);
        e++;
   }
   idx++;
}
intidx=0;
而(idx

还有无限
while循环
如果
列表1
不包含

此代码有什么问题?是否有错误消息?输出不正确?问题是,无法检查/验证数组中的单词,如果它包含特定单词,则无法循环它。我看到您在Java中,
if
是小写。在
if
语句后还有一个分号。删除它,
主题
的用途是什么?