forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloading-annimation.java
30 lines (24 loc) · 934 Bytes
/
loading-annimation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.Scanner;
public class LoadingAnimation {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the loading percentage (0-100): ");
int percentage = scanner.nextInt();
scanner.close();
if (percentage < 0 || percentage > 100) {
System.out.println("Invalid input. Percentage must be between 0 and 100.");
return;
}
int width = 50; // Width of the loading bar
int progress = (int) (width * (percentage / 100.0)); // Calculate the progress
System.out.print("Loading: [");
for (int i = 0; i < width; i++) {
if (i < progress) {
System.out.print("=");
} else {
System.out.print(" ");
}
}
System.out.println("] " + percentage + "% Complete");
}
}