"Unreachable statement" error when executing program

0

When compiling the following program in the cmd I get the error:

  

unreachable statement

public class Ejercicio1{

    public static void main(String[] args){

        //A)
        int[] f = {10,2,4,5,4,3,8,9,2,3};
        System.out.println (f[6]);

        //B)
        float g[];
        g = new float [10];
        g[5]= 5;

        //C)
        int arregloEnteros[];
        arregloEnteros = new int [1001];
        for (int i = 0; 1 <=1000; i++){
            arregloEnteros [i] = 1;
        }
        //D)
        int[] arregloA = new int[10];
        int[] arregloB= new int[20];
        for (int j = 2; j < arregloA.length; j++){
            arregloB[j]=arregloA[j-2];
        }

        //E)
        int[][] matriz = new int[3][3];
        matriz[0][0] = 1;
        matriz[0][2] = 3;
        matriz[0][1] = 2;
        matriz[1][0] = 4;
        matriz[1][1] = 5;
        matriz[1][2] = 6;
        matriz[2][0] = 7;
        matriz[2][1] = 8;
        matriz[2][2] = 9;
    }   

}
    
asked by Esteban Quito 26.09.2017 в 23:30
source

2 answers

1

The error is in section C, since this error indicates that the part of the code will never be executed:

int arregloEnteros[];
arregloEnteros = new int [1001];
for (int i = 0; 1 <=1000; i++){
    arregloEnteros [i] = 1;
}

The part of the code that would never be executed is 1 <= 1000 , so you should change it as follows:

int arregloEnteros[];
arregloEnteros = new int [1001];
for (int i = 0; i <=1000; i++){
    arregloEnteros [i] = 1;
}
    
answered by 26.09.2017 в 23:49
0

The error is due to the evaluation of the cycle in for , you are considering 1 <=1000 , which is incorrect.

for (int i = 0; 1 <=1000; i++){
    arregloEnteros[i] = 1;
}

It should be:

for (int i = 0; i <=1000; i++){
    arregloEnteros[i] = 1;
}
    
answered by 26.09.2017 в 23:49