-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistogramPatternOfArray.java
More file actions
37 lines (32 loc) · 922 Bytes
/
Copy pathHistogramPatternOfArray.java
File metadata and controls
37 lines (32 loc) · 922 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
30
31
32
33
34
35
36
37
import java.util.Scanner;
public class HistogramPatternOfArray {
static void histogram(int a[]){
for(int i=0; i<a.length; i++){
for(int j=0; j<a[i]; j++){
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
//ARRAY SIZE AND ELEMENTS INPUT
System.out.print("Enter size of array: ");
int size= sc.nextInt();
int arr[]= new int[size];
System.out.print("Enter " + size + " elements(0-9): ");
boolean flag= true;
for(int i=0; i<size; i++){
arr[i]= sc.nextInt();
}
for(int i=0; i<size; i++){
if(arr[i]<0 || arr[i]>9){
flag=false;
break;
}
}
if(flag==true){
histogram(arr);
}
}
}