Q:

Calculate The Given Number is Prime Number or Not Using Java

0

This Program is used to calculate the given number is Prime or Not Prime using Java

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

// prime or not 

import java.io.*; 

class ssva30 
{ 
public static void main(String arg[]) throws IOException 
{ 
int n,i,p=1; 
BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); 
System.out.print("\n\t\t\tChecking the Number is prime or Not"); 
System.out.println("\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); 
System.out.print("\nEnter the Value of N: "); 
n=Integer.parseInt(inp.readLine()); 
for(i=2;i<n;i++) 
{ 
if(n%i==0) 
p=0; 
} 
if(p==0) 
System.out.print("\nThis is not Prime Number\n"); 
else 
System.out.print("\nThis is Prime Number\n"); 
} 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now