Skip to content

Instantly share code, notes, and snippets.

@FareedUllah09
Created April 21, 2019 16:59
Show Gist options
  • Select an option

  • Save FareedUllah09/97b044803bfb0cca43792424ea054034 to your computer and use it in GitHub Desktop.

Select an option

Save FareedUllah09/97b044803bfb0cca43792424ea054034 to your computer and use it in GitHub Desktop.
This Program will Print out all the Prime Numbers.
The Program will ask you to enter the number to check wether it is Prime Number Or Not a Prime Number.
It will print out True If the Number is Prime and False If the Number is not Prime
import java.util.*;
public class FindPrime {
public static boolean CheckPrime(int input){
if (input % 2 != 0) {
if(input % 3 != 0) {
return true;
}
}
else {
return false;
}
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int x = 0;
boolean j;
System.out.println("Enter the number to check wether it is Prime or notPrime");
x = scanner.nextInt();
while (x > 0) {
j = CheckPrime(x);
System.out.println(j);
System.out.println("Enter a negative number to exit the loop");
System.out.println("Enter the number to check wether it is Prime or notPrime");
x = scanner.nextInt();
}
System.out.println("Loopexited You enterd a negative number");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment