import java.util.Scanner; public class LabTask7 { public static void main(String args[]) { int arr[],n,search,i; Scanner sc=new Scanner(System.in); System.out.println("Enter number of elements: "); n=sc.nextInt(); arr=new int[n]; System.out.println("Enter "+n+" elements: "); for(i=0;i<n;i++) arr[i]=sc.nextInt(); System.out.println("Enter the value to find: "); search=sc.nextInt(); for(i=0;i<n;i++) { if (arr[i]==search) { System.out.println(search+" is found at location "+(i+1)); break; } } if(i==n) System.out.println(search+" isn't found in array"); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter