This question requires that the given X be searched from the N integers entered. If it is found, the position of output X (starting from 0); if it is not found, the output is "not found ".
Input Format:
The input returns two positive integers n (<= 20), X, and N integers in row 1st. The numbers cannot exceed the length integer and are separated by spaces.
Output Format:
Output the position of X in a row, or "not found ".
Input Example 1:
5 73 5 7 1 9
Output Example 1:
2
Input Example 2:
5 73 5 8 1 9
Output Example 2:
Not found
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner cin = new Scanner(System.in);int n = cin.nextInt();int index = cin.nextInt();int[] a = new int[n];boolean flag = false;int i;for (i = 0; i < n; i++) {a[i] = cin.nextInt();if (a[i] == index) {flag = true;break;}}if (flag) {System.out.println(i);} else {System.out.println("Not Found");}}}