java是否正确地将名称和级别存储到数组?
此存储名称和级别是否正确地分配到数组
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Enter name and grade and save in an array
Scanner input = new Scanner(System.in);
String [] name = new String [50];
int [] grade = new int[50];
for (int i = 0; i < 50; i++){
System.out.println("Enter students name: ");
String studentName = input.nextLine();
name[i] = studentName;
System.out.println("Enter students grade = ");
int studentGrade = input.nextInt();
grade [i] = studentGrade;
}
}
}
# 1 楼答案
是的,您的数据已正确存储在阵列中。但是,有一些注释可以帮助您学习:
# 2 楼答案
这里有一个自己测试这个程序的方法
# 3 楼答案
对。为什么运行此代码后不能打印数组以检查是否正常
要打印数组,假设
arr
,只需执行以下操作:# 4 楼答案
我想是的,但是你最好使用hashmap,因为你想存储一个名字和这个名字的等级
数组中的这些值没有链接,例如,您不能对它们进行排序