Linear Search :Java Program

package javaPrograms;

import java.util.Scanner;


public class LinerSearch
{


static int n;


public static void main(String a[])
{


Scanner sc=new Scanner(System.in);
System.out .println("Enter the size of array");

int size=sc.nextInt();


int[] arr=new int[size];
System.out .println("Enter the values of array");

for(int i=0; i<size; i++)
 {
arr[i]=sc.nextInt();

 }

      System.out.println("Enter no.  to Search");
 int noSearch =sc.nextInt();
     boolean vFound=false;
     for(int i=0; i<size; i++)
      {
        if(noSearch==arr[i])
        {
System.out.println("value is found="+noSearch);
           vFound=true;
           break;
         }
    }

 if(!vFound)
 {
 System.out.println("value not found");
 }


}
}
Output
------------------------------------------------------------------------------------------------------------------------------
Enter the size of array
3
Enter the values of array

2
3
4
Enter no.  to Search
2
value is found=2


Post a Comment

4 Comments

  1. Replies
    1. Great Article android based projects

      Java Training in Chennai

      Project Center in Chennai

      Java Training in Chennai

      projects for cse

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. You are doing a good job and sharing your knowledge to others! it was one of the pretty post to read and useful to improve the knowledge as updated one, keep doing the good work.
    Selenium Training in Electronic City

    ReplyDelete
  3. Gone through this wonderful coures called Salesforce Certification Training in Dallas who are offering fully practical course, who parent is Salesforce Training in USA and they have students at Salesforce Training classes in Canada institutes.

    ReplyDelete
Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)