class progReport extends Thread {
// function for clearing the line by printing escape char '\b'
private static void cls(){
for (int i = 0; i <50; i++) {
System.out.print("\b");
}
} //End of cls
//Running a thread for printing the message every 100 ms.
public void run(int prog) {
int k;
cls();
try {
Thread.sleep(100);
} catch(InterruptedException e) {
e.printStackTrace();
}
System.out.print("Scanning: " + (prog) + "% ");
k=prog%3; // mod 3, so as to decide which symbol to be used for revolving animation
switch (k) {
case 0:
System.out.print("/");
break;
case 1:
System.out.print("--"); // LINE WITH THE PROBLEM
break;
default:
System.out.print("\\");
break;
} // End of switch
} // End of run
} // end of class progReport
// class with main
public class ProgressDemo {
public static void main(String...a) {
int prog = 0;
progReport pr = new progReport();
while(prog <= 100)
pr.run(prog++);
System.out.println("\nScanning Complete!!");
} // End of main
} // End of class ProgressDemo
Upon executing this code on the command line, it doesn't clear the last "-" of the case 1: in which two dash are printed "--", but if I include a single space in the other cases(i.e. changing "/" and "\\" to " /" and " \\") then it is clearing the whole line properly. Can someone help me point out why is it behaving so weird?