Skip to content

Instantly share code, notes, and snippets.

@ashutoshchauhan13
Created July 7, 2020 13:24
Show Gist options
  • Save ashutoshchauhan13/637b24483de244db016a83a9c7f45b96 to your computer and use it in GitHub Desktop.
Save ashutoshchauhan13/637b24483de244db016a83a9c7f45b96 to your computer and use it in GitHub Desktop.
public class Test {
public static void main(String[] args){
for (int i= 1; i<= 100; i++) {
if(isPrimeNumber(i)) {
System.out.println(i); //Only Print prime numbers
}
}
}
private static boolean isPrimeNumber(int num){
int number = num;
boolean value = true;
//we were missing this num check - if num is 1 return true;
if(num ==1){
return true;
}
num--;
while(num!=1){
if(number%num == 0){
value = false;
}
num--;
}
return value;
}
//Output of the program
//1
//2
//3
//5
//7
//11
//13
//17
//19
//23
//29
//31
//37
//41
//43
//47
//53
//59
//61
//67
//71
//73
//79
//83
//89
//97
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment