Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created October 4, 2020 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/d1030a81d8b94fb672cf1854bf776b4e to your computer and use it in GitHub Desktop.
Save codecademydev/d1030a81d8b94fb672cf1854bf776b4e to your computer and use it in GitHub Desktop.
Codecademy export
// Import statement:
import java.util.ArrayList;
class PrimeDirective {
// Add your methods here:
public boolean isPrime(int number){
if (number == 2){
return true;
} else if (number < 2){
return false;
}
for(int i=2; i<number; i++){
if(number%i==0){
return false;
}
}
return true;
}
public static void main(String[] args) {
PrimeDirective pd = new PrimeDirective();
int[] numbers = {6, 29, 28, 33, 11, 100, 101, 43, 89};
System.out.println(pd.isPrime(7));
System.out.println(pd.isPrime(28));
System.out.println(pd.isPrime(2));
System.out.println(pd.isPrime(0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment