Answer to Question #235133 in Java | JSP | JSF for JAykee

Question #235133

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!!!.


1
Expert's answer
2021-09-09T17:11:55-0400
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!!!.");
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS