java - I need to know why my counter variable is looping -


so have method receives string[][] , string(word).the method has word 2darray , should display 1 of other words in same row. need ignore(not display) , count(++) empty spots in same row. want know why counter looping , wont let me ignore empty spaces.

public static void main(string[] args) {      string[][] array2d = {{"joe", "slim", "ed", "george"},                           {"soto", "", "", "" },                           {"billy", "sanchez", "carlos", "fernando"}};      sort(array2d, "soto"); }  public static void sort(string[][] matrix, string word) {     int counterforarraylength = 0;     boolean random = true;     boolean exit = true;     string optionfromuser = "";     {         random = true;         (int = 0; < matrix.length; i++) {             (int j = 0; j < matrix[0].length; j++) {                 if (matrix[i][j].equals(word)) {                     (int k = 0; k < matrix[0].length; k++) {                         while (random) {                             string randomword = matrix[i][(int) (math.random() * matrix[0].length)];                             string testrandom = "" + randomword;                              if (randomword.equals(word)) {                                 random = true;                             } else {                                 if (randomword.equals("")) {                                     counterforarraylength++;                                     system.out.println("" + counterforarraylength);                                 } else {                                     joptionpane.showmessagedialog(null, randomword);                                     optionfromuser = joptionpane.showinputdialog("desea obtener otro sinonimo? si/no  \n digite salir si asi lo desea.");                                     optionfromuser = optionfromuser.tolowercase();                                     if (optionfromuser.equals("si") || optionfromuser.equals("s")) {                                         random = true;                                     } else {                                         random = false;                                     }                                 }                             }                         }                     }                 }             }         }          if (optionfromuser.equals("salir")) {             exit = false;         } else {             word = joptionpane.showinputdialog("digite otra palabra");         }     } while (exit); } 

run:

 1  2  3  4  5  6  7  8  9 10 

etc.

your code sample missing essential information. however, internal loop:

while(random) {    // . . . } 

can run forever because don't guarantee have random variable set false. work only if call method word isn't part of array. if call word = "soto" chance 100% never leave loop since out of 4 words there 1 found , other 3 empty.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -