Note that there are some explanatory texts on larger screens.

plurals
  1. POOut of bounds exception Java
    primarykey
    data
    text
    <p>This code works but it keeps giving me the array out of bounds exception.Even when I change the array size to 6 and leave 2 empty slots at the end it throws the exception. Could someone please identify the problem? </p> <pre><code> 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] &gt; 100 || arrayCMYK [0] &lt; 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] &gt; 100 || arrayCMYK [1] &lt; 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] &gt; 100 || arrayCMYK [2] &lt; 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] &gt; 100 || arrayCMYK [3] &lt; 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]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload