Save as "Search.java"...
import java.util.*;
public class Search
{
public static void main(String[] args)
{
int n , find = 0 , i , count = 0;
Scanner in = new Scanner(System.in);
int[] arr = new int[20];
System.out.println("Enter the number of elements in the array:");
n = in.nextInt();
System.out.println("Enter array elements:");
for(i=1;i<=n;i++)
arr[i] = in.nextInt();
System.out.println("Enter the element whose no of occurrence is to be found:");
find = in.nextInt();
for(i=1;i<=n;i++)
if(arr[i]==find)
count++;
if(count!=0)
System.out.println("The no of occurrence of the element is found to be:" + count);
else
System.out.println("Element not found in the array:");
}
}
import java.util.*;
public class Search
{
public static void main(String[] args)
{
int n , find = 0 , i , count = 0;
Scanner in = new Scanner(System.in);
int[] arr = new int[20];
System.out.println("Enter the number of elements in the array:");
n = in.nextInt();
System.out.println("Enter array elements:");
for(i=1;i<=n;i++)
arr[i] = in.nextInt();
System.out.println("Enter the element whose no of occurrence is to be found:");
find = in.nextInt();
for(i=1;i<=n;i++)
if(arr[i]==find)
count++;
if(count!=0)
System.out.println("The no of occurrence of the element is found to be:" + count);
else
System.out.println("Element not found in the array:");
}
}
0 comments :
Post a Comment