JOptionPane输入for循环,有两个增量

时间:2013-04-04 21:43:39

标签: java arrays swing for-loop joptionpane

好,所以我遇到以下循环问题。此循环的预期目标是userinput [k]是已在方法中按字母顺序排序的名称列表。然后,这些名称将显示在下面的InputDialog中,其中将输入表示学位的数字。

我正在尝试匹配名称和程度。例如:在循环中,第一个用户输入是userinput [0]。我希望输入的数字为bee degree [0],然后等等......

问题是我如何用J增量器存储该输入。所以我基本上得到的错误是String degree [] = Integer ......

for ( int k = 0;  k < userinput.length;  k++ ){      
     for (int j = 0; j < userinput.length; j++ ) {                    
         String input = JOptionPane.showInputDialog("Please enter the highest earned degree for the following person : " + userinput [ k ] +  "\n 1 = BS \n 2 = MS \n 3 = PhD");
         String degree[] = Integer.parseInt(input[]);
     }
}

2 个答案:

答案 0 :(得分:1)

这是你想要做的吗?

int[] degree = new int[userInput.length];
for(int k = 0; k < userInput.length; k++) {
    String input = JOptionPane.showInputDialog("Please enter the highest earned degree for the following person : " + userinput [ k ] +  "\n 1 = BS \n 2 = MS \n 3 = PhD");
    degree[k] = Integer.parseInt(input);
}

答案 1 :(得分:1)

这是你想要做的吗?

  

假设您已将userinput声明为字符串数组   一定大小并分配其值,并将声明度视为数组   相同大小的字符串。

for ( int k = 0;  k < userinput.length;  k++ ){      
         String input = JOptionPane.showInputDialog("Please enter the highest earned degree for the following person : " + userinput [ k ] +  "\n 1 = BS \n 2 = MS \n 3 = PhD");
         degree[k] = input;
     }
}