Created
October 11, 2020 13:26
-
-
Save cicorias/4240bd5dc4bcffb978b20a76da5d8839 to your computer and use it in GitHub Desktop.
java progress bar system console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void progressPercentage(int remain, int total) { | |
if (remain > total) { | |
throw new IllegalArgumentException(); | |
} | |
int maxBareSize = 10; // 10unit for 100% | |
int remainProcent = ((100 * remain) / total) / maxBareSize; | |
char defaultChar = '-'; | |
String icon = "*"; | |
String bare = new String(new char[maxBareSize]).replace('\0', defaultChar) + "]"; | |
StringBuilder bareDone = new StringBuilder(); | |
bareDone.append("["); | |
for (int i = 0; i < remainProcent; i++) { | |
bareDone.append(icon); | |
} | |
String bareRemain = bare.substring(remainProcent, bare.length()); | |
System.out.print("\r" + bareDone + bareRemain + " " + remainProcent * 10 + "%"); | |
if (remain == total) { | |
System.out.print("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment