1Now let’s see print first 10 prime numbers in java.
2
3public class FirstTenPrimeNumbers
4{
5 public static void main(String[] args)
6 {
7 int count = 0, number = 0, a = 1, b = 1;
8 while(number < 10)
9 {
10 b = 1;
11 count = 0;
12 while(b <= a)
13 {
14 if(a%b == 0)
15 count++;
16 b++;
17 }
18 if(count == 2)
19 {
20 System.out.printf("%d ", a);
21 number++;
22 }
23 a++;
24 }
25 }
26}
1public class Prime {
2
3 public static void main(String[] args) {
4
5 int num = 29;
6 boolean flag = false;
7 for(int i = 2; i <= num/2; ++i)
8 {
9 // condition for nonprime number
10 if(num % i == 0)
11 {
12 flag = true;
13 break;
14 }
15 }
16
17 if (!flag)
18 System.out.println(num + " is a prime number.");
19 else
20 System.out.println(num + " is not a prime number.");
21 }
22}