以下是一个Java程序,用于检查数组是否包含给定值。
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"); } } } }
输出结果
Array contains the given element