Created
October 29, 2017 14:49
-
-
Save PocasPedro/507ef3b54ed9f74c5ec1c49c8a38d8bc to your computer and use it in GitHub Desktop.
Java Fundamentals for Kids - Exercise 18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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