配列のキーとなる要素を検索するJavaプログラムです。
配列のサイズを入力し、その配列のすべての要素を入力する。次に、検索したい要素を入力します。forループの助けを借りて、要素の場所を簡単に見つけることができます。

以下は、配列内のキー要素を検索するJavaプログラムのソースコードです。Javaプログラムは正常にコンパイルされ、Windowsシステム上で実行されます。プログラムの出力も以下に示す。

```
import java.util.Scanner;
public class Search_Element
{
    public static void main(String[] args) 
    {
        int n, x, flag = 0, i = 0;
        Scanner s = new Scanner(System.in);
        System.out.print("Enter no. of elements you want in array:");
        n = s.nextInt();
        int a[] = new int[n];
        System.out.println("Enter all the elements:");
        for(i = 0; i < n; i++)
        {
            a[i] = s.nextInt();
        }
        System.out.print("Enter the element you want to find:");
        x = s.nextInt();
        for(i = 0; i < n; i++)
        {
            if(a[i] == x)
            {
                flag = 1;
                break;
            }
            else
            {
                flag = 0;
            }
        }
        if(flag == 1)
        {
            System.out.println("Element found at position:"+(i + 1));
        }
        else
        {
            System.out.println("Element not found");
        }
    }
}
```

出力する：

```
$ javac Search_Element.java
$ java Search_Element
 
Enter no. of elements you want in array:7
Enter all the elements:
2
4
1
5
7
6
9
Enter the element you want to find:5
Element found at position:4
```
This is a Java Program to Search Key Elements in an Array.
Enter the size of array and then enter all the elements of that array. Now enter the element you want to search for. With the help of for loop we can find out the location of the element easily.

Here is the source code of the Java Program to Search Key Elements in an Array. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

import java.util.Scanner;
public class Search_Element
{
    public static void main(String[] args) 
    {
        int n, x, flag = 0, i = 0;
        Scanner s = new Scanner(System.in);
        System.out.print("Enter no. of elements you want in array:");
        n = s.nextInt();
        int a[] = new int[n];
        System.out.println("Enter all the elements:");
        for(i = 0; i < n; i++)
        {
            a[i] = s.nextInt();
        }
        System.out.print("Enter the element you want to find:");
        x = s.nextInt();
        for(i = 0; i < n; i++)
        {
            if(a[i] == x)
            {
                flag = 1;
                break;
            }
            else
            {
                flag = 0;
            }
        }
        if(flag == 1)
        {
            System.out.println("Element found at position:"+(i + 1));
        }
        else
        {
            System.out.println("Element not found");
        }
    }
}


Output:

$ javac Search_Element.java
$ java Search_Element
 
Enter no. of elements you want in array:7
Enter all the elements:
2
4
1
5
7
6
9
Enter the element you want to find:5
Element found at position:4