Write a program to input a number and check whether it is prime or not. Today we are going to discuss about the above mentioned topic. We have provided important details along with suitable example.
Prime numbers are natural numbers greater than 1 that have no positive divisors other than 1 and themselves. They are the building blocks of the natural numbers. As every natural number greater than 1 can be uniquely represented as a product of prime numbers. A concept known as prime factorization.
Understanding and efficiently identifying prime numbers is essential in various computational tasks and mathematical investigations. Algorithms for checking primality, like the Sieve of Eratosthenes and probabilistic primality tests, are continuously researched and optimized for improved performance and accuracy.
import java.io.*;
public class test
{
public static void main(String args[])throws IOException
{
int num;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a Number");
num = Integer.parseInt(br.readLine());
int prime = 1;
for (int x = 2;x < num; x++)
{
if(num % x==0)
{
prime = 0;
break;
}
}
if(prime == 1)
System.out.println("Number is prime number.");
else
System.out.println("Number is not a prime number.");
}
}
In the above post we have discussed a program which is mostly asked by computer science students. In the program we have discussed how to check whether number is prime or not. For more such related posts please visit pour blog regularly.
Thank you!!
Making money as a coder in 2025 is not much of a big or tough…
Lloyds Technology Centre, A tech and data company located in Hyderabad, India. They are part of…
How to Increase Height at Any Age Rise Above: How to Increase Height at Any…
In the fast-paced digital world, we often forget the timeless beauty that nature offers. Today,…
Top 10 Deadliest Kicks in Martial Arts: Master the Art of Knockouts Martial arts is…
How to Optimize Battery Life of Your Smartphone: Tips and Tricks for Prolonging Battery Health…