Hey guys I am taking a high school course for computer science and we just started our second unit arrays and I am not sure how to do a problem.
So I need to make code that checks if a user inputted value is in an array. So what I've got so far is:
import java.util.Scanner;
public class array1 {
public static void main(String[]args) {
int [] arraynumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Scanner sc = new Scanner(System.in);
System.out.println("Enter a value");
int num = sc.nextInt();
}
}
This is what I've got so far, and I have no idea how to check if this value exists in the array I created. I had checked other results but could not find one that was in my learning range.
So is there a way to check if a value stated by a user exists in an array?
num.