Skip to main content
Post Undeleted by 200_success
Added more explanation
Source Link

This also seems to workEach line of your output is the same as the previous but with one character different. Thus a StringBuilder can be used to hold the string such that it can be manipulated. The StringBuilder can be converted into a String at any point for display purposes.

StringBuilder sb = new StringBuilder("OOOOOOOOOO");
for (int i = 0; i < 10; i++)
{
    sb.setCharAt(i, 'X');
    System.out.println(sb);
}

This also seems to work...

StringBuilder sb = new StringBuilder("OOOOOOOOOO");
for (int i = 0; i < 10; i++)
{
    sb.setCharAt(i, 'X');
    System.out.println(sb);
}

Each line of your output is the same as the previous but with one character different. Thus a StringBuilder can be used to hold the string such that it can be manipulated. The StringBuilder can be converted into a String at any point for display purposes.

StringBuilder sb = new StringBuilder("OOOOOOOOOO");
for (int i = 0; i < 10; i++)
{
    sb.setCharAt(i, 'X');
    System.out.println(sb);
}
Post Deleted From Review
Source Link

This also seems to work...

StringBuilder sb = new StringBuilder("OOOOOOOOOO");
for (int i = 0; i < 10; i++)
{
    sb.setCharAt(i, 'X');
    System.out.println(sb);
}