Home » Sometech » WAP in Java to check whether the number is prime or not.

WAP in Java to check whether the number is prime or not.

Java Coding

import java.util.Scanner;

class prime

{

public static void main(String arg[])

{

int n,i;

Scanner ss=new Scanner(System.in);

System.out.println(“Enter the number”);

n=ss.nextInt();

for(i=2;i<n;i++)

{

if(n%i==0)

{

System.out.println(“Not Prime”);

break;

}

}

if(i==n)

System.out.println(“Prime”);

}

}

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: