Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public class LoopArraysProgram
  2. {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. System.out.println("Please enter the size of your data (n) " +
  7. "set followed by n numbers to visualise: ");
  8. int n = IOUtil.readInt();
  9. double data[] = new double[n];
  10. for (int i = 0 ; i < n ; i++)
  11. data[i] = IOUtil.readDouble();
  12.  
  13. System.out.println("Please enter a minimum, maximum and number" +
  14. " of buckets to print a histogram with:");
  15.  
  16. double min = IOUtil.readDouble();
  17. double max = IOUtil.readDouble();
  18. int nrBuckets = IOUtil.readInt();
  19.  
  20. int v[] = LoopArraysLibrary.frequencyTable(min, max, nrBuckets, data);
  21.  
  22. int ymax = LoopArraysLibrary.maximum(v) + 2;
  23.  
  24. char h[][] = new char[ymax][v.length + 1];
  25.  
  26. for (int i = 0 ; i <= ymax - 2 ; i++) {
  27. h[i][0] = '|';
  28. for (int j = 1 ; j <= v.length ; j++)
  29. h[i][j] = ' ';
  30. }
  31.  
  32. h[ymax-1][0] = '+';
  33.  
  34. for (int i = 1 ; i <= v.length ; i++) {
  35. h[ymax-1][i] = '-';
  36. for (int j = ymax - 2; j >= ymax - 1 - v[i-1] ; j--)
  37. h[j][i] = '#';
  38. }
  39.  
  40. //5 -1.1 1.1 1.2 -0.8 1.6
  41.  
  42. for (int i = 0 ; i < ymax ; i++)
  43. {
  44. for (int j = 0 ; j < v.length + 1 ; j++)
  45. System.out.print(h[i][j]);
  46. System.out.println();
  47. }
  48.  
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement