-4
    String [] vKeywordsArray;
    int vNumberofKeywords = Integer.parseInt(JOptionPane.showInputDialog("How many keywords do you want to enter?"));
    vKeywordsArray = new String[vNumberofKeywords];  
    int i=0;
    while (i < vNumberofKeywords)
    {
         vKeywordsArray[i] = JOptionPane.showInputDialog("Please enter your keyword to be stored in index " +i+ ".");
         i++;
    }
    JOptionPane.showMessageDialog(null, "Thank you for the input(s).");          
    for (int j=0; j < vKeywordsArray.length; j++)
    {
       String vKeywords = JOptionPane.showInputDialog("What would you like to talk about today?");
       boolean vCheck = vKeywords.contains(vKeywordsArray[j]);
       while (vCheck == false)
       { 
           vKeywords = JOptionPane.showInputDialog("Sorry I did not get that, please enter one of the relevant keywords mentioned earlier.");
       }
    }
}
4
  • 6
    while (vCheck == false) <- if that loop is entered how would vCheck ever become true? You don't change it in the loop after all.
    – user6073886
    Mar 29, 2018 at 15:38
  • 1
    @OHGODSPIDERS, that should be an answer
    – smac89
    Mar 29, 2018 at 15:39
  • How can I fix this? Im so confused. Im still very new to java programming. Mar 29, 2018 at 15:40
  • 1
    @smac89 I'd rather have question like this silently dissappear with 0 answers by the automatic cleanup system ;)
    – user6073886
    Mar 29, 2018 at 15:40

3 Answers 3

0

in the loop

while( vCheck == false){
    vKeywords = jOptionPane.showInputDialog("Sorry I did not get that, please enter one of the relevant keywords mentioned earlier.");
}

you never update your vCheck condition. Since the vCheck remains false the loop will continue forever.

0

instead of while loop you need a if condition actually like below. I did not find any reason for a while loop there because in the while loop you are displaying a message and for that you don't need a loop at all.

while (vCheck == false)
   { 
       vKeywords = JOptionPane.showInputDialog("Sorry I did not get that, please enter one of the relevant keywords mentioned earlier.");
   }

Change it to:-

  if (vCheck == false)
   { 
       vKeywords = JOptionPane.showInputDialog("Sorry I did not get that, please enter one of the relevant keywords mentioned earlier.");
   }
0

You need to reevaluate your boolean vCheck variable after you receive your new input from the user.

while (vCheck == false)
{ 
    vKeywords = JOptionPane.showInputDialog("Sorry I did not get that, please enter one of the relevant keywords mentioned earlier.");
    vCheck = vKeywords.contains(vKeywordsArray[j]);
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.