Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

array contains java

import java.util.Scanner;
import java.util.Arrays;
public class ArrayContains {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the number of elements ");
        int elements = input.nextInt();

        System.out.println("Enter the " + elements + " numbers");
        int[] numbers = new int[elements];

        for (int i = 0; i < numbers.length; i++) {
            System.out.println("Please enter number");
            numbers[i] = input.nextInt();
        }
        System.out.println("Check if number is inside of an array");
        int n = input.nextInt();
        if (Arrays.asList(elements).contains(n)) {
            System.out.println("True");
        } else {
            System.out.println("False");
        }
    }
}
 
PREVIOUS NEXT
Tagged: #array #java
ADD COMMENT
Topic
Name
3+5 =