java 命令行中显示进度信息

来源:互联网 发布:电梯运行优化sas 编辑:程序博客网 时间:2024/05/21 08:37
class ShowGra implements Runnable{private int percent;public ShowGra(int per){this.percent = per;}public void run(){int i;for(int j=0;j<30;j++)System.out.print("\b");for(i=0;i<percent/5;i++){System.out.print("=");}int blanks = 25-i;for(int k=0;k<blanks;k++)System.out.print(" ");System.out.printf("%3d%%",percent);}}public class Test{public Test(){}public static void main(String[] args){int per = 0;while(per<=100){Runnable run2 = new ShowGra(per);Thread thread2 = new Thread(run2);thread2.start();try{Thread.sleep(1000);}catch(Exception e){;}finally{per+=5;}}}}