Header Ads

Java Program to Find Number is Prime Or Not

What is Prime Number?
A number that is greater than One and divisible only by 1 and itself
For Example:  2, 3, 5,7,11,13,17, 19……..

Java, Program, prime, Print, Fibonacci, Series, prime number, find Fibonacci series, java program, find number is prime, check the number is prime, Java Program to Find Number is Prime


Example: Code Program


import java.util.*;
public class PrimeNum {

     public static void main(String[] args) {
          // TODO Auto-generated method stub
          Scanner sc = new Scanner(System.in);
          int num, i, f = -1;
          System.out.print("Enter Number:");
          num = sc.nextInt();
          i = 2;
          while(i<num/2) {
              if(num%i == 0)
                   f += 1;
              i+=1;
          }
          if(f == -1)
              System.out.print(num+" is Prime");
          else
              System.out.print(num+" is Not Prime");

     }

}

Output:

Java, Program, prime, Print, Fibonacci, Series, prime number, find Fibonacci series, java program, find number is prime, check the number is prime, Java Program to Find Number is Prime


Python Program Code

No comments

Powered by Blogger.