0
while(count <= maxNum){
     System.out.println("O-------O");
     System.out.printf("|" + "%8s", count + "|");
     System.out.println("O-------O");
     count++;
     startTime = System.currentTimeMillis();
     //an empty loop! does nothing except keeps checking the continuation condition
     //continues as long as the time that has passed is less than millisToWait
     while(System.currentTimeMillis() - startTime < millisToWait);
  System.out.println("O-------O");

Above is the part of code that conecerns the actual output of what I am trying to achieve. The code, for the most part works as intended, except the output(below is the output attached as an image) is not 100% correct. There is an extra "O-------O" to the right of every number.

Here's the output

Correct me if I'm wrong, but I believe it has something to do with the first println statement, but I'm still not sure how it's printing once on top and then once to the side. Any help is appreciated.

1 Answer 1

1

Printf doesn't automaticly add a newline, you have to do that manually by adding a newline character into the string. We use %n instaid of \n for portability reasons. The format can also be simplified.

Change the third line to:

System.out.printf("|%8s%n|", count);
Sign up to request clarification or add additional context in comments.

2 Comments

Wow. That one modification fixed it. Thank you so much.
@shmosel Thanks, I added it into the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.