Thursday, September 16, 2010

Find the Number

import java.util.Scanner;

public class FindTheNumber
{
    public static void main (String[] args)
    {
    Scanner scan = new Scanner(System.in);
    System.out.println ("Enter 5 numbers");
    int num1 = scan.nextInt();
    int num2 = scan.nextInt();
    int num3 = scan.nextInt();
    int num4 = scan.nextInt();
    int num5 = scan.nextInt();

    int out=0;
    System.out.println ("Please enter the number you would like to check for: ");
    int num = scan.nextInt();
    if (num==num1)
        out= 1;
    if (num==num2)
        out= 1;
    if (num==num3)
        out= 1;
    if (num==num4)
        out= 1;
    if (num==num5)
        out= 1;
    if (out==1)
        System.out.println ("Yes, the number is here");
    else
        System.out.println ("No, the number is not here");


    }
}

The answer will output "yes" if the number is in the list. The answer will output "no" if it is not. The program will end no matter when it runs through once.

No comments:

Post a Comment