Today We will create a java program to take input of number and check weather it is a prime number or not using java So Lets Get Started
import java.util.Scanner;
public class Prime {
public static void main(String[] args) {
int number;
Scanner sc=new Scanner(System.in);
System.out.print("Enter number: ");
number=sc.nextInt();
int n=2, mid=number/2;
boolean primetest = true;
do {
if (number % n == 0) {
System.out.println("A factor "+n+" of "+number+" found!");
System.out.println("Hence NOT a prime number11");
primetest=false;
break;
}
n++;
}
while(n<=mid);
if(primetest==true){
System.out.println(number+" is a Prime Number");
}
}}
Explaining The Above Program Step By Step
Today we have learned how to input a number and test if it is a prime number
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…