Lesson Progress

0% Complete

**Prime number in Java: Prime number is a number that is greater than 1 and divided by 1 or itself only. **

**In other words, prime numbers can’t be divided by other numbers than itself or 1. For example 2, 3, 5, 7, 11, 13, 17…. are the prime numbers.**

Example Code or Prime Number Finder

```
import java.util.Scanner;
public class PrimeNo {
public static void main(String[] args) {
int i=2;
Scanner sc = new Scanner(System.in);
System.out.println("enter a no.");
int no = sc.nextInt();
while( i< no)
{
if(no % i ==0)
{
System.out.println("your no is not prime");
break;
}
i++;
}
if (i == no)
{
System.out.println("your no is prime");
}
}
}
```