错误:
不兼容的类型:void无法转换为String
目标:我想从用户输入中获取学生姓名
这是我的代码
public class HelloWorld {
final static int NUM_STUDENTS = 5;
final static int NUM_TESTS = 4;
public static void main(String[] args) {
String[] studentNames = getStudentNames();
double[][] gradebook = getGradebook();
printGradeBook(studentNames, gradebook);
}
public static String[] getStudentNames() {
String[] studentName = new String[5];
for (int i = 0; i < studentName.length; i++) {
studentName[i] = JOptionPane.showInputDialog("Enter a name" + (i + 1) + ": ");
}
return studentName;
}
答案 0 :(得分:0)
想发表评论,但我没有足够的代表
您发布的代码确实有效,您可能想要获得一个学生的姓名。在这种情况下,只需循环遍历它们并将其添加到String。
String studentName = "";
for (String s: studentNames) {
if(s.equals("Name you're looking for")){
studentName = s;
}
}