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
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
3 Comments
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletePython Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city
Great Article android based projects
DeleteJava 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
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.
ReplyDeleteSelenium Training in Electronic City