Advertisement
unknown_0711

Untitled

Dec 24th, 2022
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n];
  6.  
  7. int max = Integer.MIN_VALUE;
  8. for (int i = 0; i < n; i++) {
  9. arr[i] = sc.nextInt();
  10. max = Math.max(max, arr[i]);
  11. }
  12. sc.close();
  13. barGraph(arr, n);
  14. }
  15.  
  16. public static void barGraph(int[] arr, int n)
  17. { int max = Integer.MIN_VALUE;
  18. for (int i = 0; i < n; i++) max = Math.max(max, arr[i]);
  19. for (int i = 0; i < max; i++)
  20. {
  21. for (int val : arr)
  22. {
  23. if (val >= max - i) { System.out.print("*\t"); }
  24. else { System.out.print("\t"); }
  25. }
  26.  
  27. System.out.println();
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement