Computer Science, asked by agraharidevesh658, 12 hours ago

Write a program to accept 10 different numbers in a Single DimensionalArray (SDA). Now, enter a number and search whether the number ispresent or not in the list of array elements by using the 'Linear Search'technique.Sample Input:n[01n[lln[21n[31n[41n[51n[61n[7]n[9174566277466759804226Enter a number to be searched: 42The number is present​

Answers

Answered by guptarahulalwaysonl9
1

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

 System.out.println("Enter the numbe rof elements in the array");

 int n = sc.nextInt();

 for(i=0;i<n;i++){

     arr[i] = sc.nextInt();

 }

 System.out.println("Enter the element to be searched");

 int key = sc.nextInt();

 for(int i=0;i<n;i++){

     if(arr[i] == key){

         System.out.println("Key found at index" +i);

         System.exit(0);

     }

 }

 System.out.println("Element not foun the array");

}

}

Explanation:

Give proper input output  format

Similar questions