To search a number by Linear Search


/*Write a program in java assign 10 different number in a single Dimensional Array and search whether a given number is present or not and display the relevant message.*/


import java.io.*;

Public class ser

{

public static void  main (String arg[])throws IOException

{

InputStreamReader r1=new InputStreamReader (System.in);

BufferedReader in=new BufferedReader(r1);

int i,j,k,m;

k=0;

int m[]=new int[10];

for(i=0;i<=10;i++)

{

System.out.println(“enter the number in the cell:”);

m[i]=Integer.parseInt(in.readLine());

}

System.out .println(“Enter the number to be searched”);

j= Integer.parseInt(in.readLine());

for(i=0;i<=10;i++)

{

if(m[i]==j)

k=1;

}

if(k==1)

System.out.println(“The required number “+j+” is present”);

Else

System.out.println(“The required number “+j+” is not present”);

}}

Related Posts

Comments are closed.