Embed presentation
Download to read offline
![//Ques. 1 WAP to find out whether the number is prime or not ?
importjava.util.Scanner;
class prime
{
public static void main(String arr[])
{
intn,c=1,i=2;
Scanner in = new Scanner(System.in);
System.out.print("n Enter a Number = ");
n = in.nextInt();
for (i=2;i<=2;i++)
{
if (n%2==0||n%3==0)
{
c=0;
break;
}
}
if (c==1)
System.out.println( n+ " is Prime Number");
else
System.out.println(n+ " is not a Prime Number");
}
}](https://image.slidesharecdn.com/prime-131127075638-phpapp01/75/WAP-to-find-out-whether-the-number-is-prime-or-not-in-java-1-2048.jpg)


This Java program uses a for loop to check if a user-input number is prime or not. The program takes the number as input, divides it by all integers from 2 to the number/2, and checks if any division results in a remainder of 0. If no remainders are 0, the number is prime and the program prints that it is prime; otherwise, it is not prime and the program prints that it is not prime.
![//Ques. 1 WAP to find out whether the number is prime or not ?
importjava.util.Scanner;
class prime
{
public static void main(String arr[])
{
intn,c=1,i=2;
Scanner in = new Scanner(System.in);
System.out.print("n Enter a Number = ");
n = in.nextInt();
for (i=2;i<=2;i++)
{
if (n%2==0||n%3==0)
{
c=0;
break;
}
}
if (c==1)
System.out.println( n+ " is Prime Number");
else
System.out.println(n+ " is not a Prime Number");
}
}](https://image.slidesharecdn.com/prime-131127075638-phpapp01/75/WAP-to-find-out-whether-the-number-is-prime-or-not-in-java-1-2048.jpg)
