以下の課題をやっているのですが、array を作る段階でつまづいてしまい困っています。
java
1コード
import java.util.Scanner; // Needed for Scanner class
/**
This program demonstrates how the user may specify an
array's size.
*/
public class ExamA
{
public static void main(String[] args)
{
double numStudents; // The number of tests
double[] tests; // Array of test scores
// Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Get the number of test scores. System.out.print("How many tests do you have? "); numStudents = keyboard.nextDouble(); // Create an array to hold that number of scores. tests = new double[numStudents]; String[] names = new String[numStudents]; // Get the individual test scores. for (int index = 0; index < tests.length; index++) { System.out.print("Enter test score " + (index + 1) + ": "); tests[index] = keyboard.nextDouble(); } for (int index = 0; index < names.length; index++) { System.out.print("Enter student name " + (index + 1) + ":"); names[index] = keyboard.nextLine(); } // Display the test scores. System.out.println(); System.out.println("Here are the scores you entered:"); for (int index = 0; index < tests.length; index++) System.out.print(tests[index] + " ");
}
}