目录

效果

代码


效果

java 控制台 输出进度条_System

代码

public static void main(String[] args) {
    int total = 100;
     for (int i = 0; i < total; i++) {
         System.out.print(GetProces(total, i+1));
         try {
             Thread.sleep(20);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
     }}
static String GetProces(int total, int finish) {
     StringBuilder str = new StringBuilder();
     str.append("\r完成[");
     for (int i = 0; i < total; i++) {
         if (i > finish) {
             str.append(" ");
         } else if (i == finish) {
             str.append(">");
         } else {
             str.append("=");
         }
     }
     str.append("]" + finish + "%");
     return str.toString();
 }public static void main(String[] args) {

    int total = 100;
    for (int i = 0; i < total; i++) {
        System.out.print(GetProces(total, i+1));
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

static String GetProces(int total, int finish) {
    StringBuilder str = new StringBuilder();
    str.append("\r完成[");
    for (int i = 0; i < total; i++) {
        if (i > finish) {
            str.append(" ");
        } else if (i == finish) {
            str.append(">");
        } else {
            str.append("=");
        }
    }
    str.append("]" + finish + "%");
    return str.toString();
}
public static void main(String[] args) {

    int total = 100;
    for (int i = 0; i < total; i++) {
        System.out.print(GetProces(total, i+1));
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

static String GetProces(int total, int finish) {
    StringBuilder str = new StringBuilder();
    str.append("\r完成[");
    for (int i = 0; i < total; i++) {
        if (i > finish) {
            str.append(" ");
        } else if (i == finish) {
            str.append(">");
        } else {
            str.append("=");
        }
    }
    str.append("]" + finish + "%");
    return str.toString();
}