write a program in Java to input 10 numbers in an array input a number and search if the number is present in the array or not using Linear search
Answers
Answered by
5
Answer:
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int arr[] = {10,20,30,40,50,60,70,80,90,100};
System.out.println("Enter a Number To be Searched in the Array using Linear search");
int num = sc.nextInt();
for(int i = 0 ; i < 11 ; i++ ){
if(arr[i] == num ){
System.out.println("Number "+num+" Found At "+( i + 1 )+" position in the array");
break;
}
}
}
}
Similar questions