所以我需要幫助。我使用循環(huán)來檢查數(shù)組。但是,我需要循環(huán)顯示僅在檢查數(shù)組的所有索引后才找到的名稱。我已經(jīng)嘗試了此代碼的許多變體。但是,我無法讓它工作。它要么在檢查所有代碼之前中斷,要么將 JOptionPane 框循環(huán) 20 次(這不是我想要的),要么顯示正確的結(jié)果然后顯示錯誤消息。這是我的代碼:private static String[]name= new String [20];public static int i=0;name[i]= JOptionPane.showInputDialog(null, "Please enter admin's name into the database:");String search= JOptionPane.showInputDialog(null,"Please enter admin's name to check the database:"); for (int j=0;j<name.length;j++){ if (search.equals(name[j])){ JOptionPane.showMessageDialog(null,"Name : " +name[j]); break; else if(!search.equals(name[j])){ JOptionPane.showMessageDialog(null, name[j]+ "was not found"); } }
java你如何使用if else語句使循環(huán)保持循環(huán)
繁華開滿天機(jī)
2021-06-13 17:15:11