Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n];
- int max = Integer.MIN_VALUE;
- for (int i = 0; i < n; i++) {
- arr[i] = sc.nextInt();
- max = Math.max(max, arr[i]);
- }
- sc.close();
- barGraph(arr, n);
- }
- public static void barGraph(int[] arr, int n)
- { int max = Integer.MIN_VALUE;
- for (int i = 0; i < n; i++) max = Math.max(max, arr[i]);
- for (int i = 0; i < max; i++)
- {
- for (int val : arr)
- {
- if (val >= max - i) { System.out.print("*\t"); }
- else { System.out.print("\t"); }
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement