Is there a way to prompt a user, using consecutive JOptionPane Input Dialog's, for consecutive array input storages? Maybe I'm not great at asking the question, so please refer to the following example...

  titleInputs[x] = JOptionPane.showInputDialog(null, "Please enter a book title, or zzz to    
      quit:");
  authorInputs[x] = JOptionPane.showInputDialog(null, "Please enter " + titleInputs[x] + "'s 
      author's last name, or zzz to quit: ")
  pageInputs[x] = JOptionPane.showInputDialog(null, "Please enter " + titleInputs[x] + "'s page 
      count, or zzz to quit: ")

Can you find the first titleInput, followed by another inputDialog asking for author, and lastly followed by pageCount? All while referring to the initial title for the selection in which you're querying?

The following are the desired outcome: For title #1 Please enter a title: Please enter "title's" author: Please enter "title's" page count: For title #2 Please enter a title: Please enter "title's" author: Please enter "title's" page count: ...continue until all 5 titles are collected...

有帮助吗?

解决方案

int x = 0;
string currTitle = "";
do
{
  currTitle = JOptionPane.showInputDialog(null, "Please enter a book title, or zzz to quit:");
  if(!currTitle.equals("zzz"))
  {
    titleInputs[x] = currTitle;
    authorInputs[x] = JOptionPane.showInputDialog(null, "Please enter " + titleInputs[x] + "'s author's last name: ");
    pageInputs[x] = JOptionPane.showInputDialog(null, "Please enter " + titleInputs[x] + "'s page count: ");
    x = x+1;
  }
} while(!currTitle.equals("zzz")) //if you wanted, you could do: while(!currTitle.equals("zzz") && x < MAX_ARRAY_SIZE) ...obviously after declaring MAX_ARRAY_SIZE somewhere.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top