Created
April 21, 2019 16:59
-
-
Save FareedUllah09/97b044803bfb0cca43792424ea054034 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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