1. Engineering
  2. Computer Science
  3. here is what i have ignore the random generator i...

Question: here is what i have ignore the random generator i...

Question details

PP 8.3 Write a program that creates a histogram that allows you to visually inspect the frequency distribution of a set of values. The program should read in an arbitrary number of integers from a text input fle that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range l to 10, 11 to 20, and so on. Print one asterisk for each value entered. 110** 21 30 **xx 31 40 4150 *xx 51 60 * 61 70 I 71 80 8190* 91 100*xx

Here is what I have. Ignore the random Generator. I want to Input data NO FILE. I Cannot use a file I need to input the data No file or Io. , not Random Please. Show Comments and Please Explain I always give a like. No File!

import java.util.Scanner;
public class Hiss


{

//main method

public static void main(String[] args)

{

//variables required for manipulations

int i,num;

//array to hold numbers between 1 and 100

int[] anum = new int[100];

//array to hold the count of numbers in the range

int[] histogram = new int[10];

//for loop to generate 100 numbers and find their groups

System.out.println("The random generated data is :");

for(i=0; i<100; i++)

{
Scanner scan = new Scanner(System.in);

  

num= scan.nextInt();

  
  

//condition to count the numbers in respective groups

//count numbers in group 1 - 10
while (num <0 && num> 101){

if(num >=1 && num<=10){

histogram[0]++;
num= scan.nextInt();}

//count numbers in group 11 - 20

else if(num >=11 && num<=20){

histogram[1]++;
num= scan.nextInt();}

//count numbers in group 21 - 30

else if(num >=21 && num<=30){

histogram[2]++;
num= scan.nextInt();
}

//count numbers in group 31 - 40

else if(num >=31 && num<=40){

histogram[3]++;
num= scan.nextInt();
}

//count numbers in group 41 - 50

else if(num >=41 && num<=50){

histogram[4]++;
num= scan.nextInt();
}

//count numbers in group 51 - 60

else if(num >=51 && num<=60){

histogram[5]++;
num= scan.nextInt();
}

//count numbers in group 61 - 70

else if(num >=61 && num<=70){

histogram[6]++;
num= scan.nextInt();
}

//count numbers in group 71 - 80

else if(num >=71 && num<=80){

histogram[7]++;
num= scan.nextInt();
}

//count numbers in group 81 - 90

else if(num >=81 && num<=90){

histogram[8]++;
num= scan.nextInt();}

//count numbers in group 91 - 100

else{

histogram[9]++;
num= scan.nextInt();
}

}
}
  

System.out.println(" The histogram of the data : ");

//loop to print the histogram

for(i=0; i<10; i++)

{

System.out.print((i*10+1)+" - " +((i+1)*10)+":");

for(int j=0; j<histogram[i]; j++)

System.out.print("*");

System.out.println();

}

}

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution