Unreachable code error with no return [closed] Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Unreachable code error with no return [closed] without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have a program I was working on and suddenly started getting unreachable code errors at my return in my columns() method. I tried any line and it won’t say anything but unreachable code. The line “return obj” is the line that can’t be reached. My code is below:

public class Display {

public static void main(String[] args){
    int x,y;
    for(int a = 1; a < 5; a++){
        System.out.print(a + "t");
    }

    System.out.println();
    for(int i = 0; i < 10; i++){
        y = i;
        x = 1;
        for(int z = 0; z < 4; z++) {
            System.out.print(x*y + "t");
            x++;
        }
    System.out.println();   
    }
}

public static Object[] columns() {  
    Object[] obj;
    obj = new Object[11];
    obj[0] = "x = 1, 2, 3, 4";
    for(int o = 0; 0 < 10;o++){
        obj[o+1] = "x * " + o;
    }
    return obj;
}
}

Answer

Your problem is here:

for(int o = 0; o < 10;o++){
    obj[o+1] = "x * " + o;
}
return obj;

You are using 0<10 this loop never ends.

We are here to answer your question about Unreachable code error with no return [closed] - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji