java - Data Validation - do while loop -


i having trouble validation of string input. want make user cannot enter invalid string (only "cis 280", "acc 201", "cis 120", "cis 185"). however, cannot figure out how strings.

my problems are

  1. when enter valid input, program exits , not display corresponding time.
  2. when enter invalid input in first input dialog, program enters infinite loop, when enter valid string at:

    invalid = joptionpane.showinputdialog("please enter valid class."); 
public class arraytest {     public static void main(string[] args) {         int = 0;         string classinput;         boolean valid = false;         string invalid;         string[][] classnames = {           {"cis 280", "acc 201", "cis 120", "cis 185"},           {"tue 5:00", "mon & weds 12:20", "mon & weds 10:10", "mon & weds 12:00" }         };         classinput = joptionpane.showinputdialog("please input class name: ");          {             (i = 0; < classnames[0].length; ++i) {                 if(classnames[0][i].equals(classinput)) {                     valid = true;                 }             }             if(valid == false) {                 invalid = joptionpane.showinputdialog("please enter valid class.");                 classinput.equals(invalid);             }         } while(valid == false);          joptionpane.showmessagedialog(null, "the time of class is: " + classnames[1][i]);     } } 

instead of

get users input do{    validate input    if input wrong ask again //btw here error,                                 //check storing user's input }while(input wrong) 

try

do{    users input    validate input }while(input wrong) 

another thing iterating till end of row make i equal of length of row. need stop iterating when find correct value use i in

joptionpane.showmessagedialog(null, "the time of class is: " + classnames[1][i]); 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -