Java Saved Program: gifted-life

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


import java.util.*;
import java.lang.*;
import java.io.*;
 

class Linearsearch
{
	public static void main (String[] args)
	{
	
       int i,num,val,arr[];
       Scanner sc=new Scanner(System.in);
       System.out.println("Enter  the n integer:\n");
       num=sc.nextInt();
       System.out.println("Enter the elements:\n");
       arr=new int[num];
       for(i=0;i<num;i++){
           arr[i]=sc.nextInt();
       }
       System.out.println("Enter the search value:\n");
       val=sc.nextInt();
       for(i=0;i<num;i++){
           if(arr[i]==val)
           System.out.println(val+"position is:"+(i+1));
           
       }
    }
}

	
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs