[Solved] How do I reverse a generic For loop [closed]


Based on provided results, you need updated first loop and second. Fist loop should start from 9 as you already printed mid line in previous part. And second loop should iterate to counter of fist loop to achieve what you except:

public static void main(String[] args) {
    for (int i = 10; i >= 1; i--) {
        for (int j = 10; j >= i; j--) {
            if (j % 2 == 0) {
                System.out.print("*");
            } else {
                System.out.print("-");
            }
        }
        System.out.println();
    }

    for (int i = 9; i >= 0; i--) {
        for (int j = 0; j < i; j++) {
            if (j % 2 == 0) {
                System.out.print("*");
            } else {
                System.out.print("-");
            }
        }
        System.out.println();
    }
}

So resulted output:

*
*-
*-*
*-*-
*-*-*
*-*-*-
*-*-*-*
*-*-*-*-
*-*-*-*-*
*-*-*-*-*-
*-*-*-*-*
*-*-*-*-
*-*-*-*
*-*-*-
*-*-*
*-*-
*-*
*-
*

1

solved How do I reverse a generic For loop [closed]