Computer Science, asked by Anmolsingh0021, 6 days ago

. Write a program to accept 10 element of an integer array from the user and search
whether the entered number is present in the array or not. Print the position of the
searched element in the list. Print an appropriate message if element not found in
the list

Answers

Answered by at209575
1

Answer:

import java.util.Scanner;

public class KboatSDASearch

{

public void search(int m[], int ns) {

boolean found = false;

for (int i = 0; i < m.length; i++) {

if (m[i] == ns) {

found = true;

break;

}

}

if (found)

System.out.println("Number is present");

else

System.out.println("Number is not present");

}

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int arr[] = new int[10];

System.out.println("Enter 10 numbers");

for (int i = 0; i < arr.length; i++) {

arr[i] = in.nextInt();

}

System.out.print("Enter number to search: ");

int num = in.nextInt();

KboatSDASearch obj = new KboatSDASearch();

obj.search(arr, num);

}

}

Similar questions