このコードは機能しますが、配列の範囲外の例外が引き続き発生します。配列のサイズを 6 に変更し、最後に 2 つの空のスロットを残しても、例外がスローされます。誰かが問題を特定できますか?
int [] arrayCMYK = new int [4];
getCMYK(arrayCMYK);
static int getCMYK (int arrayCMYK[])
{
Scanner input = new Scanner(System.in);
//C
System.out.println("\n\nPlease Enter the 'C' value of the CMYK number.");
System.out.println("Press Enter after the number has been entered.");
arrayCMYK[0] = input.nextInt();
while(arrayCMYK [0] > 100 || arrayCMYK [0] < 0 )
{
System.out.println("\n\nError\nPlease Enter the 'C' value of the CMYK number.");
System.out.println("Press Enter after the number has been entered.");
arrayCMYK[0] = input.nextInt();
}
//M
System.out.println("\n\nPlease Enter the 'M' value of the CMYK number.");
System.out.println("Press Enter after the number has been entered.");
arrayCMYK[1] = input.nextInt();
while(arrayCMYK [1] > 100 || arrayCMYK [1] < 0 )
{
System.out.println("\n\nError\nPlease Enter the 'M' value of the CMYK number.");
System.out.println("Press Enter after the number has been entered.");
arrayCMYK[1] = input.nextInt();
}
//Y
System.out.println("\n\nPlease Enter the 'Y' value of the CMYK number.");
System.out.println("Press Enter after the number has been entered.");
arrayCMYK[2] = input.nextInt();
while(arrayCMYK [2] > 100 || arrayCMYK [2] < 0 )
{
System.out.println("\n\nError\nPlease Enter the 'Y' value of the CMYK number.");
System.out.println("Press Enter after the number has been entered.");
arrayCMYK[2] = input.nextInt();
}
// K
System.out.println("\n\nPlease Enter the 'K' value of the CMYK number.");
System.out.println("Press Enter after the number has been entered.");
arrayCMYK[3] = input.nextInt();
while(arrayCMYK [3] > 100 || arrayCMYK [3] < 0 )
{
System.out.println("\n\nError\nPlease Enter the 'K' value of the CMYK number.");
System.out.println("Press Enter after the number has been entered.");
arrayCMYK[3] = input.nextInt();
}
return arrayCMYK[4];