Skip to content

Instantly share code, notes, and snippets.

@PocasPedro
Created October 29, 2017 14:49
Show Gist options
  • Save PocasPedro/507ef3b54ed9f74c5ec1c49c8a38d8bc to your computer and use it in GitHub Desktop.
Save PocasPedro/507ef3b54ed9f74c5ec1c49c8a38d8bc to your computer and use it in GitHub Desktop.
Java Fundamentals for Kids - Exercise 18
public class CheckExistence {
public static void main(String[] args) {
//Define & Initialization
int numbers[] = new int[] {1,333,17,6,47,8,14,43};
int numbertocheck = 2;
boolean exists = false;
for(int i = 0 ; i < numbers.length ; i ++){
if ( numbers[i] == numbertocheck)
exists = true;
}
if (exists == true){
System.out.println("The number " + numbertocheck + " exists on the array!");
} else {
System.out.println("The number " + numbertocheck + " does not exist on the array!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment