-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarChart.java
More file actions
29 lines (27 loc) · 783 Bytes
/
BarChart.java
File metadata and controls
29 lines (27 loc) · 783 Bytes
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 BarChart{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int [] arr = new int[n];
for(int i = 0; i < arr.length; i++){
arr[i] = scn.nextInt();
}
int max = arr[0];
for(int i = 1; i < arr.length; i++){
if(arr[i] > max){
max = arr[i];
}
}
for(int floor = max; floor >= 1; floor--){
for(int i = 0; i <arr.length; i++){
if(arr[i] >= floor){
System.out.print("*\t");
}else{
System.out.print("\t");
}
}
System.out.println();
}
}
}