Program : Check Number is Prime or Not in JAVA - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Program : Check Number is Prime or Not in JAVA

Write a program a to check number is prime or not?
public class PrimeNum {
    public static void main(String[] args) {
        int number=20;
        int temp=0;
        for (int i=2;i<=number-1;i++)
           {
            if(number%i==0){
                temp=temp+1;
            }
        }
        if(temp==0){
            System.out.println(number+" is prime number");
        }
        else {
            System.out.println(number+" is not prime number");
        }
    }

}
Output : 




Start with your Choice

-Important Programs for Freshers

Sorting and Searching Programs
Learn Pattern Programs 
Click to learn Array Programs
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!

No comments:

Pages