Develop a program using array that accepts three input values from the keyboard. Then it should also accept a number to search. This number is to be searched if it is among the three input values. If it is found, display the message “Search number is found!!!”, otherwise display “Search numbers is lost!!!.
import java.util.Scanner;
public class Main
{
public static int Search(int[] arr, int num){
for(int i=0;i<arr.length;i++){
if(arr[i] == num){
return 1;
}
}
return -1;
}
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
int [] arr= new int[3];
System.out.println("Enter three numbers: ");
for(int i=0;i<3;i++){
arr[i]=in.nextInt();
}
int num;
System.out.println("Enter number to search: ");
num=in.nextInt();
int r=Search(arr,num);
if (r==1)
System.out.println("Search number is found!!!");
else
System.out.println("Search numbers is lost!!!.");
}
}
Comments
Leave a comment