How do you write a java program that is run on a command prompt and
which displays a progress as:
Status x of 100%
Without going to the nextline. i.e only x keeps changing from 1 to 100
on the same line.
1 comment(s) to... “question 17”
I here will post some java/j2ee questions found and the answers. Please feel free to comment also suggesting answers. This blog is dedicated for discussion and new thoughts. Please email new questions at jvquestions@gmail.com. I would post it on the blog.
1 comments:
The answer lies in java basics, using, escape characters’.. Specifically
‘\b’(backspace).. Here is code snippet for achieving the desired result.
public static void main(String[] args) {
System.err.print("Status: completed 0 of 100%");
for(int i=1; i<=100; ++i) {
pause();
System.err.print("\b\b\b\b\b\b\b\b\b" + i + " of 100%");
}
System.err.println();
}
static void pause() {
try {
Thread.sleep(1000);
} catch(InterruptedException e) {
}
}
Post a Comment