Program to find the position of the given element present in the Array
Program to find the position of the given element present in the Array
I/P:
5
7 8 11 12 3
11
O/P:
3
I/P:
5
7 8 11 12 3
5
O/P:
element is not found
PROGRAM:
import java.util.*;
public class Kposition {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int iNum=sc.nextInt();
int iArr[]=new int[iNum];
int iCount=0;
for(int i=0;i<iNum;i++)
{
iArr[i]=sc.nextInt();
}
int k=sc.nextInt();
for(int i=0;i<iNum;i++)
{
if(iArr[i]==k)
{
System.out.println(i+1);
iCount++;
}
}
if(iCount==0)//1!=0
{
System.out.println("element is not found");
}
}
}
// 5
// 7 8 11 12 3
// 11
// 3
Comments
Post a Comment