Java program to check prime number

Java program to check prime number


import static java.lang.System.out;
import java.util.Scanner;
public class Prime_no
    public static void main(String args[])
    {   int flag=0;
        out.println("Enter a number to check it is prime or not");
        Scanner Sc= new Scanner(;
        int x= Sc.nextInt();

        for(int i=2;i<=x/2;i++)
            if (x % i == 0 )
                flag = 1;
            out.println("1 is neither prime nor composite");
        if(flag==0 && x!=1)
            out.println("Given no:"+x+" is prime number");
            out.println("The given number:"+x+" is not prime number");

Output: 01

Java program to check prime number

Output: 02

Output: 03

About the Author: Make toss

Leave a Reply

Your email address will not be published. Required fields are marked *