Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoopArraysProgram
- {
- public static void main(String[] args) {
- System.out.println("Please enter the size of your data (n) " +
- "set followed by n numbers to visualise: ");
- int n = IOUtil.readInt();
- double data[] = new double[n];
- for (int i = 0 ; i < n ; i++)
- data[i] = IOUtil.readDouble();
- System.out.println("Please enter a minimum, maximum and number" +
- " of buckets to print a histogram with:");
- double min = IOUtil.readDouble();
- double max = IOUtil.readDouble();
- int nrBuckets = IOUtil.readInt();
- int v[] = LoopArraysLibrary.frequencyTable(min, max, nrBuckets, data);
- int ymax = LoopArraysLibrary.maximum(v) + 2;
- char h[][] = new char[ymax][v.length + 1];
- for (int i = 0 ; i <= ymax - 2 ; i++) {
- h[i][0] = '|';
- for (int j = 1 ; j <= v.length ; j++)
- h[i][j] = ' ';
- }
- h[ymax-1][0] = '+';
- for (int i = 1 ; i <= v.length ; i++) {
- h[ymax-1][i] = '-';
- for (int j = ymax - 2; j >= ymax - 1 - v[i-1] ; j--)
- h[j][i] = '#';
- }
- //5 -1.1 1.1 1.2 -0.8 1.6
- for (int i = 0 ; i < ymax ; i++)
- {
- for (int j = 0 ; j < v.length + 1 ; j++)
- System.out.print(h[i][j]);
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement