If you can use commons-lang3:
public static void main(String[] args) {
// Algorithm 1
String o = null;
for (int i = 0; i < 10; i++) {
String x = StringUtils.repeat("X", i+1);
o =StringUtils.repeat("0", 9-i);
System.out.println(x+o);
}
}
[StringUtils.repeat
](https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringUtils.html#repeat(java.lang.String, int)) is a helper method, which will print a character n times.
So I create a string with n times a X
and then I do it same with o for the rest and concatenate it for output.
The solution makes your code shorter, more readable, and it uses well tested functions from third party distributor. Why invent the wheel again?