我想創建一個循環,要求掃描器在數組中以一定數量輸入每個數字(我在考慮10)。有什麼建議麼?爲陣列掃描器創建一個循環
import java.util.Scanner;
public class AssignSeven
{
public static void main(String[] args)
{
int [] array1 = new int[10];
System.out.println("Enter 10 numbers");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = 0; i < 9; i++)
{
array1[i] = a;
}
}
}
你只要求輸入一次。 – Carcigenicate
它應該是'array1 [i] = sc.nextInt();' – Saravana