Answers for "how to find contain elements in array in java"

0

how to find contain elements in array in java

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 "how to find contain elements in array in java"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language