import java.util.Scanner;
public class StudentScoresApp {
public static Score score = new Score();
private static Student student;
public static void main(String[] args) {
System.out.println("Welcome to the Student Scores Application.\n");
getStudentScores();
}
public static void getStudentScores() {
Scanner input = new Scanner(System.in);
System.out.println("Enter number of students to enter: ");
int num = input.nextInt();
int [] a = new int[num];
for (int i = 0 ; i < num ; i++); {
System.out.print("Enter Student " + (i + 1) + " last name:");
a[i] = in.nextInt();
}
}
}
, 어쨌든 그것은 당신의 디자인을 결정하는 당신까지, 배열 사이의 연결을 처리 할 수있는 좋은 방법이 아닙니다. 그렇게하고 싶다면 @Mikhail Vladimirov의 제안이 필요합니다.
한편으로는 필요에 맞게 클래스를 디자인하고 클래스의 개체를 배열이나 목록에 저장하십시오. 메인 클래스에서
public class StudentScore{
String firstName;
String lastName;
int grade;
pulbic StudnetScore(String firstName, String lastName, int grade){
this.firstName = firstName;
this.lastName = lastName;
this.grade = grade;
}
//getters(), setters()
}
:
StudentScore[] studentScores = new StudentScore[num];
for (int i = 0; i < studentScores.length; i++){
System.out.print ("Enter Student " + (i + 1) + " last name:");
String lastName = in.nextLine();
System.out.print ("Enter Student " + (i + 1) + " first name:");
String firstName = in.nextLine();
System.out.print ("Enter Student " + (i + 1) + " grade:");
int grade = in.nextInt();
studentScores[i] = new StudentScore(firstName,lastName,grade);
}
* 나는 데 문제 * : WHICH 문제? 또한 int에 성을 저장하는 방법은 무엇입니까? –