此商店名称和等级是否正确存储到数组?

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;

        }
    }
}

最佳答案

这是一种自己测试该程序的方法...

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;

  // Using print statements to check the values in your array...
  System.out.println("Name stored in name array is " + name[i]);
  System.out.println("Grade stored in grade array is " + grade[i]);
}

关于java - 此商店名称和等级是否正确存储到数组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5518818/

10-13 05:25