- Related Questions & Answers
- Java program to print prime numbers below 100
- Prime number program in Java.
- Python Program for Efficient program to print all prime factors of a given number
- C Program for efficiently print all prime factors of a given number?
- Java Program to find largest prime factor of a number
- Java Program to display a prime number less than the given number
- Print the nearest prime number formed by adding prime numbers to N
- Python Program to Check Prime Number
- Java program to print a multiplication table for any number
- Java program to print Fibonacci series of a given number.
- Java Program to find Product of unique prime factors of a number
- Java program to print odd and even number from a Java array.
- Program to print prime numbers in a given range using C++ STL
- C++ Program to Check Prime Number By Creating a Function
- Python program to print all Prime numbers in an Interval

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Any whole number which is greater than 1 and has only two factors that is 1 and the number itself, is called a prime number. Other than these two number it has no positive divisor. **For example** −

7 = 1 × 7

Few prime number are − 1, 2, 3, 5 , 7, 11 etc.

1. Take integer variable A 2. Divide the variable A with (A-1 to 2) 3. If A is divisible by any value (A-1 to 2) it is not prime 4. Else it is prime

import java.util.Scanner; public class PrimeNumber { public static void main(String args[]){ int loop, number; int prime = 1; Scanner sc = new Scanner(System.in); System.out.println("Enter a number ::"); number = sc.nextInt(); for(loop = 2; loop < number; loop++) { if((number % loop) == 0) { prime = 0; } } if (prime == 1) System.out.println(number+" is a prime number"); else System.out.println(number+" is not a prime number"); } }

Enter a number :: 2 2 is a prime number

Advertisements