A priceless Frequency of element in an array program
For more programshttps://wordpress-343193-1101484.cloudwaysapps.com/count-words-start-and-end-with-a-vowel
Write a program to print the frequency of element in an array.
For more programs
An excellent String program to count words start and end with a vowel
import java.io.*;
class frequency
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the size of the array");
int n=Integer.parseInt(br.readLine());
int Arr[]=new int[n];
int FREQ[]=new int[n];
int visited=-1;
System.out.println("Enter the values");
for(int i=0;i<n;i++)
{
Arr[i]=Integer.parseInt(br.readLine());
}
for(int i=0;i<n;i++)
{
int count=1;
for(int j=i+1;j<n;j++)
{
if(Arr[i]==Arr[j])
{
count ++;
FREQ[j]=visited;
}
}
if(FREQ[i]!=visited)
{
FREQ[i]=count;
}
}
System.out.println("------------------------------------------");
System.out.println("ELEMENT"+"\t"+"FREQUENCY");
System.out.println("------------------------------------------");
for(int i=0;i<n;i++)
{
if(FREQ[i]!=visited)
{
System.out.println(Arr[i]+"\t"+FREQ[i]);
}
}
}
}Output:
Enter the size of the array
4
10
20
10
15
ELEMENT FREQUENCY
10 2
20 1
15 1
For java videos click
https://www.youtube.com/user/trushna.tej
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.