Create a program that will accept 20 numbers and arrange them in ascending order. The program should determine the distinct numbers and the number of occurrences for each number (or the frequency). Display the supplied values, the distinct numbers and the frequency of each distinct numbers.

Your program should use three arrays that will hold the entered numbers, distinct numbers, and the frequency, respectively.

Use the following numbers in your first run:
1 37 25 1 56 8 6 9 11 8 54 56 20 25 1 8 6 20 56 56

Enter 20 numbers:
1
37
25
1
56
8
6
9
11
8
54
56
20
25
1
8
6
20
56
56
Your entered numbers are:
20 37 25 1 56 8 6 9 11 23 54 56 20 25 1 8 56 20 56 56

Distinct Number Frequency
1 3
37 1
25 2
56 4
8 3
6 2
9 1
11 1
54 1
20 2


..could you please help me on this one..i already made the arranging part..but how would i show the frequency..please help..

Edited 6 Years Ago by ayesha08: n/a

Have you sorted the given array of 20 numbers in ascending order ??

If yes, then all those duplicates would be adjacent. Ex : 1 2 3 2 would turn out as 1 2 2 3. So, now try to count those duplicates. That would be the frequency.

Have you sorted the given array of 20 numbers in ascending order ??

If yes, then all those duplicates would be adjacent. Ex : 1 2 3 2 would turn out as 1 2 2 3. So, now try to count those duplicates. That would be the frequency.

..yep..i had it arranged in an ascending order..but i'm not sure if my code is right..but it runs..
..on second thought..i think its wrong..i definitely didn't got the point..

..please help..i'm really having a hard time here..just a newbie..

Edited 6 Years Ago by ayesha08: n/a

please show us your code..!

import java.util.*;

class arrayz {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
int num=0;
int d=0;
int[] arrayz;
int i=0;

System.out.println("How many numbers in the array?");
num=scanner.nextInt();

arrayz = new int[num];

while (i<num)
{
System.out.println("Please enter a number in the array");
d=scanner.nextInt();
arrayz[i]=d;
i=i+1;
}
i=1;


while (i<num)
{
int j=i;
int B=arrayz[i];
i=i+1;

while ((j>0)&& (arrayz[j-1] > B))
{
arrayz[j] = arrayz[j-1];
j--;
arrayz[j] = B;
}
}
i=0;

System.out.println("Your aray in ascending order is");

while (i<num)
{
System.out.print(arrayz[i]+ " "); i=i+1;

}

}
}
import java.util.*;

class arrayz {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
int num=0;
int d=0;
int[] arrayz;
int i=0;

System.out.println("How many numbers in the array?");
num=scanner.nextInt();

arrayz = new int[num];

while (i<num)
{
System.out.println("Please enter a number in the array");
d=scanner.nextInt();
arrayz[i]=d;
i=i+1;
}
i=1;


while (i<num)
{
int j=i;
int B=arrayz[i];
i=i+1;

while ((j>0)&& (arrayz[j-1] > B))
{
arrayz[j] = arrayz[j-1];
j--;
arrayz[j] = B;
}
}
i=0;

System.out.println("Your aray in ascending order is");

while (i<num)
{
System.out.print(arrayz[i]+ " "); i=i+1;

}

}
}

Read your question carefully,

Your program should use three arrays that will hold the entered numbers, distinct numbers, and the frequency, respectively.

you didn't use three arrays in your program...! be accurate with your question

Read your question carefully,

Your program should use three arrays that will hold the entered numbers, distinct numbers, and the frequency, respectively.

you didn't use three arrays in your program...! be accurate with your question

Yep..that was my mistake..sorry..could you please help me out..

i'm not really getting it..please..

first Array = Supplied values,
second Array = Distinct values ( number of columns must be equal to the number of distinct values,
3rd Array = Set its length to the number of distinct values, increment to specific index every time the number appear in the first array using loop.

thats it

first Array = Supplied values,
second Array = Distinct values ( number of columns must be equal to the number of distinct values,
3rd Array = Set its length to the number of distinct values, increment to specific index every time the number appear in the first array using loop.

thats it

..ahkie..

..tnx for the help

^^,

first Array = Supplied values,
second Array = Distinct values ( number of columns must be equal to the number of distinct values,
3rd Array = Set its length to the number of distinct values, increment to specific index every time the number appear in the first array using loop.

thats it

..ok..

..tnx for the help..

^^

first Array = Supplied values,
second Array = Distinct values ( number of columns must be equal to the number of distinct values,
3rd Array = Set its length to the number of distinct values, increment to specific index every time the number appear in the first array using loop.

thats it

..hi..

..i have already made the first array..how would i start on the second array??
..what statement should i use..please help..

..pls help..

..how could i add these two arrays in my program??

..it must appear like this:

Enter 20 numbers:
1
37
25
1
56
8
6
9
11
8
54
56
20
25
1
8
6
20
56
56

Your entered numbers are:
1 1 1 6 6 8 8 8 9 11 20 20 25 25 37 54 56 56 56

Distinct Number	Frequency
1			3
6 			2
8 			3
9 			1
11			1
20 			2
25 			2
37 			1
54			1
56 			4

..heres the output of my code though:

Your entered numbers are:
1 1 1 6 6 8 8 8 9 11 20 20 25 25 37 54 56 56 56

i still lack the 2nd ant third array..
..how do i put it in??can you please give me a hand on this..
..here's my code:

import java.util.*;
  class arrayz {
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);

      int num=0;
      int d=0;
      int[] arrayz;
      int i=0;

      System.out.println("How many numbers in the array?");
      num=scanner.nextInt();

      arrayz = new int[num];

      while (i<num)
      {
      System.out.println("Please enter a number in the array");
      d=scanner.nextInt();
      arrayz[i]=d;
      i=i+1;
      }

      i=1;
      while (i<num)
      {
      int j=i;
      int B=arrayz[i];
      i=i+1;

      while ((j>0)&& (arrayz[j-1] > B))
      {
      arrayz[j] = arrayz[j-1];
      j--;
      arrayz[j] = B;
      }
      }
      i=0;

      System.out.println("Your aray in ascending order is");

      while (i<num)
      {
      System.out.print(arrayz[i]+ " "); i=i+1;


  } 
 }
}

..tnx for any help..

^_^

This article has been dead for over six months. Start a new discussion instead.