Just a simple ternary using the two loops : for(int i = 0; i < 10 ; ++i){ for(int j = 0; j < 10 ; ++j){ System.out.print(j <= i ? 'x' : 'o'); } System.out.println(); } It's a simple matrix that you want to split by a diagonal. The logic is simple. If x (aka i) > y (aka j), you are one the right of the diagonal.