{}
run-icon
Main.java
import java.util.Scanner; class LinearSearch { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("enter the size of array="); int n=sc.nextInt(); int [] arr =new int[n]; System.out.println("\n enter the elements of array="); for(int i=0;i<n; i++){ arr[i]=sc.nextInt(); } System.out.print("enter the searching element ="); int item=sc.nextInt(); boolean flag=false; for(int i=0; i<n; i++){ if(arr[i]==item){ flag=true; break; } } if(flag==true) System.out.println("element found"); else System.out.println("element not found"); } }
Output