문제

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