java 控制台示例中的Java进度条

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 控制台示例中的Java进度条相关的知识,希望对你有一定的参考价值。

/**
 * Prints progress in command line, but slows down the process itself.
 * Usage example: printProgBar(100 * i / total);
 * NOTE: first must be 100 
 * @param percent 
 * @see http://nakkaya.com/2009/11/08/command-line-progress-bar/
 */
public static void printProgBar(int percent) {
    StringBuilder bar = new StringBuilder("[");

    for (int i = 0; i < 50; i++) {
        if (i < (percent / 2)) {
            bar.append("=");
        } else if (i == (percent / 2)) {
            bar.append(">");
        } else {
            bar.append(" ");
        }
    }

    bar.append("]   ").append(percent).append("%     ");
    System.out.print("\r" + bar.toString());
}

以上是关于java 控制台示例中的Java进度条的主要内容,如果未能解决你的问题,请参考以下文章