该代码假设打印用户输入的名称,但它只是打印空值而不是打印实际名称。我正在使用数组来存储名称值。
import javax.swing.JOptionPane;
class PrintName {
public static void main(String[] args) {
int nameCount = Integer.parseInt(JOptionPane.showInputDialog(null, " how many NAMES you want to enter?"));
String [] userFirstName = new String [nameCount];
String [] userLastName = new String [nameCount];
for (int i=0; i<nameCount; i++) {
fullName(userFirstName[i], userLastName[i]);
}
for (int i=0; i<nameCount; i++) {
JOptionPane.showMessageDialog(null, userFirstName[i] + "\n" + userLastName[i]);
}
public static void fullName (String firstName, String nLastName) {
firstName = JOptionPane.showInputDialog(null, "What's your first name?");
nLastName = JOptionPane.showInputDialog(null, "What's your last name?");
}
}