Free Java Programs
Write a program to search a numbers from given list
import java.io.*;
class search
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int arr[]=new int[10],i,temp,j,num;
System.out.println("Enter an array of 10 numbers");
for(i=0;i<10;i++)
{
arr[i]=Integer.parseInt(br.readLine());
}
System.out.println("Enter number to be searched");
num=Integer.parseInt(br.readLine());
for(i=0;i<10;i++)
{
if(num==arr[i])
{
System.out.println("Number found on position ="+(i+1));
break;
}
}
if(i==10)
System.out.println("Number not found");
}
}
Write a program to search a numbers from given list
import java.io.*;
class search
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int arr[]=new int[10],i,temp,j,num;
System.out.println("Enter an array of 10 numbers");
for(i=0;i<10;i++)
{
arr[i]=Integer.parseInt(br.readLine());
}
System.out.println("Enter number to be searched");
num=Integer.parseInt(br.readLine());
for(i=0;i<10;i++)
{
if(num==arr[i])
{
System.out.println("Number found on position ="+(i+1));
break;
}
}
if(i==10)
System.out.println("Number not found");
}
}
sir in ths programming there is no any use of verible"temp" then why it is taken??????
ReplyDelete