This is a java program to find prime number. it find a number is prime or not .
prime  number is a number which is divisible by one or that number not others.

Source Code:

  1. public class PrimeNumber {
  2. public static void main(String[] args) {
  3. try (Scanner input = new Scanner(System.in)) {
  4. int i,num,count = 0;
  5. System.out.println("Enter the positive number:");
  6. num = input.nextInt();
  7. for(i=2;i<num;i++) {
  8. if(num%i==0) {
  9. count++;
  10. break;
  11. }
  12. }
  13. if(count==0)
  14. System.out.println("This is prime number.");
  15. else
  16. System.out.println("This is not prime number.");
  17. }
  18. }
  19. }

Output:

Enter the positive number:
5
This is prime number.

Enter the positive number:
153
This is not prime number.

0 comments:

Post a Comment