我对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);
关于java - 从另一个类中的数组列表值将 int 分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20302933/