Java Program to Check if An Array Contains a Given Value

Java Programming Java8Object Oriented Programming

Following is a Java program to check if An Array Contains a Given Value.

Example

Live Demo

public class Sample {
   public static void main(String args[]){
      int[] myArray = {55, 45, 69, 44};
      int num = 55;

      for(int i = 0; i<myArray.length; i++){
         if(num == myArray[i]){
            System.out.println("Array contains the given element");
         }
      }
   }
}

Output

Array contains the given element
raja
Published on 26-Apr-2018 11:12:09
Advertisements