Note that there are some explanatory texts on larger screens.

plurals
  1. POjava: Find integer's frequency in an array
    primarykey
    data
    text
    <p>I need to develop a <code>java</code> program that asks the user to enter some <code>integers</code> and find the largest, and smallest number, and the average of those numbers. Then, divides the <strong>set of array</strong> into a number of <strong>sub-intervals</strong> that the user specifies, then it generates a boundary points each has a length of sub-interval width..</p> <p>The problem is that I need to create a frequency:</p> <p>ex: Interval: </p> <p>14.5-16.5 </p> <p>Frequency: 1 (here it should shows how many integers belong to this boundaries)</p> <p>Interval: </p> <p>16.5-18.5 </p> <p>Frequency: 4 and so on.</p> <p>Here is the code I have so far, almost done except finding the frequency of each boundary..</p> <pre><code>import java.util.Scanner; public class Sta { public static void main(final String args[]) { final Scanner input = new Scanner(System.in); int num=0; int range=0; int subnum; int subwid; System.out.print("How many numbers do you want to enter: "); num=input.nextInt(); final int array[]=new int[num]; System.out.print("Enter the numbers now: "); for(int i=0; i&lt;array.length; i++) { array[i]=input.nextInt(); } System.out.print("These are the numbers you entered:\n"); printArray(array); int smallest=array[0]; int largest=array[0]; for (final int element : array) { if(element&gt;largest) { largest=element; } else if(element&lt;smallest) { smallest=element; } range=largest-smallest; } System.out.printf("Largest is %d\n",largest); System.out.printf("Smallest is %d\n",smallest); System.out.printf("Range is %d\n",range); System.out.print("Enter the number of subinterval: "); subnum=input.nextInt(); subwid=range/subnum; System.out.printf("The width of subinterval is %d\n", subwid); /* this part should find the boundaries and find the elements that fall between the each two boundaries */ for(double boundary=smallest-.5; boundary &lt;=largest+.5; boundary +=subwid) { System.out.printf("Boundaries are %.1f\n",boundary); for(int element=0; element&lt;array.length; element++) { if(element&gt;=boundary) { System.out.printf("f=%d\n",element); } } } } public static void printArray(final int arr[]) { for (final int element : arr) { System.out.print(element + "\n"); } } } </code></pre> <p>The question is how do I find the frequencies as in the above table example ??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload