
以下の課題をやっているのですが、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] + " ");
}
}
質問文のソースコードはインデントを訂正してcodeタグで囲ってくださいな。
コードブロックが用いられている他の質問/回答を適当に覗いて、同じようになるまで試行錯誤してみてください。いちおうリンクも貼っときます。https://teratail.com/help/question-tips#questionTips3-5
あと、画像がとんでもなく見づらいです。必要に応じて抜粋してテキストで書いてください。画像のまま貼るにしても、トリミングしたり、明暗を調整したり、向きを揃えたりするなどの配慮をしてください。