Question

Basically the error holds that I want the third loop to start increasing from what the second loops integer was. For example, Second loop is 0, third loop starts at 0, finished, second loop initializes and now is 1, third loop starts at 1, finished, second loop initializes and now is 2, third loop starts at 2, and so on.

If you don't understand that then I am lost for you but now for the code.

J is not increasing but integer is, i isn't or row isn't either. Thanks if you can solve.

public class Hello {

public static int integer = 0;

public static void fixThisMethod() {

    for(int row = 0; row < 10; row++)//Matrices Row
    {
        for(int i = 0; i < 10; i++)
        {
            integer = i;

            for(int j = integer; j < 10; integer++)
            {
                System.out.println("Started From: " + integer + " Now On: " + j);
            }
        }
    }
}

public static void main(String[] args) {
    fixThisMethod();
}

}

Was it helpful?

Solution

    public static int integer = 0;

public static void fixThisMethod() {

    for(int row = 0; row < 10; row++)//Matrices Row
    {
        for(int i = 0; i < 10; i++)
        {
            integer = i;

            for(int j = integer; j < 10; integer++,j++)
            {
                System.out.println("Started From: " + integer + " Now On: " + j);
            }
        }
    }
}

public static void main(String[] args) {
    fixThisMethod();
}

Your output

Started From: 8 Now On: 8

Started From: 9 Now On: 9 Started From: 1 Now On: 1 Started From: 2 Now On: 2 Started From: 3 Now On: 3 Started From: 4 Now On: 4 Started From: 5 Now On: 5 Started From: 6 Now On: 6 Started From: 7 Now On: 7 Started From: 8 Now On: 8 Started From: 9 Now On: 9 Started From: 2 Now On: 2 Started From: 3 Now On: 3 Started From: 4 Now On: 4 Started From: 5 Now On: 5 Started From: 6 Now On: 6 Started From: 7 Now On: 7 Started From: 8 Now On: 8 Started From: 9 Now On: 9 Started From: 3 Now On: 3 Started From: 4 Now On: 4 Started From: 5 Now On: 5 Started From: 6 Now On: 6 Started From: 7 Now On: 7 Started From: 8 Now On: 8 Started From: 9 Now On: 9 Started From: 4 Now On: 4 Started From: 5 Now On: 5 Started From: 6 Now On: 6 Started From: 7 Now On: 7 Started From: 8 Now On: 8 Started From: 9 Now On: 9 Started From: 5 Now On: 5 Started From: 6 Now On: 6 Started From: 7 Now On: 7 Started From: 8 Now On: 8 Started From: 9 Now On: 9 Started From: 6 Now On: 6 Started From: 7 Now On: 7 Started From: 8 Now On: 8 Started From: 9 Now On: 9 Started From: 7 Now On: 7 Started From: 8 Now On: 8 Started From: 9 Now On: 9 Started From: 8 Now On: 8 Started From: 9 Now On: 9 Started From: 9 Now On: 9 Error

java.lang.IllegalMonitorStateException
at java.lang.Object.notifyAll(Native Method)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top