Answers for "Create a program to determine if an array contains a given number."

0

Create a program to determine if an array contains a given number.

public class Contains {

    public static void main(String[] args) {
        int[] num = {1, 2, 3, 4, 5};
        int toFind = 3;
        boolean found = false;

        for (int n : num) {
            if (n == toFind) {
                found = true;
                break;
            }
        }

        if(found)
            System.out.println(toFind + " is found.");
        else
            System.out.println(toFind + " is not found.");
    }
}
Posted by: Guest on November-30-2020

Code answers related to "Create a program to determine if an array contains a given number."

Code answers related to "TypeScript"

Browse Popular Code Answers by Language