我对Java和IM都很陌生,在制作学生记录系统的过程中。
我目前坚持尝试将年份类的数组列表中的先前指定整数(学生所在的年份)分配给结果类中的新变量,以便用户可以输入学生所述年份的结果在。
这是我的代码
class StudentYear
{
public void StudentYear()
{
ArrayList<Integer> studentYear = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the year the student has most recently completed: ");
studentYear.add(sc.nextInt());
System.out.println(studentYear);
}
}
class Results
{
public void Results()
{
ArrayList<Integer> results = new ArrayList<Integer>();
int year = // need to put arraylist value(0) from studentYear
System.out.println("Please enter the results for "+year+":");
Scanner sc = new Scanner(System.in);
results.add(sc.nextInt());
System.out.println(results);
}
}
最佳答案
使用get(int)函数从列表中检索值:
int year = studentYear.get(0);