Skip to content

Instantly share code, notes, and snippets.

@wbminsssss
Last active May 28, 2024 06:05
Show Gist options
  • Select an option

  • Save wbminsssss/78970ce9d3638d7892bcc6e1e39877f0 to your computer and use it in GitHub Desktop.

Select an option

Save wbminsssss/78970ce9d3638d7892bcc6e1e39877f0 to your computer and use it in GitHub Desktop.
控制台输出一个进度条
/**
* 控制台输出一个进度条
* 例如 测试 => [##################################################] 12/12 (100%)
*
* @param prefixStr 进度条前缀
* @param total 总进度
* @param current 当前进度
*/
public static void consoleProgressBar(String prefixStr, int total, int current) {
int percent = (int) ((double) current / total * 100);
int filled = (int) Math.round(((double) current / total) * 50);
String bar = "[" + "#".repeat(filled) + " ".repeat(50 - filled) + "] ";
System.out.print("\r" + prefixStr + " => " + bar + current + "/" + total + " (" + percent + "%)");
if (current == total) {
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment