Display First 10 Prime Numbers | Java Programs

Output:

*** First 10 Prime Numbers ***

First 10 prime numbers are:
2
3
5
7
11
13
17
19
23
29

Click Here For Java Online Compiler

Solution:

public class First10PrimeNumbers {

    public static void main(String args[]) {
        int n;
        int status = 1;
        int num = 3;
        System.out.println("*** First 10 Prime Numbers ***" + "\n");
        System.out.println("First 10 prime numbers are:");
        System.out.println(2);
        for (int i = 2; i <= 10;) {
            for (int j = 2; j <= num / 2; j++) {
                if (num % j == 0) {
                    status = 0;
                    break;
                }
            }
            if (status != 0) {
                System.out.println(num);
                i++;
            }
            status = 1;
            num++;
        }
    }
}
Share This :

Related Post

avatar


It is nice article to improve my knowledge.thank you for sharing useful post
visit
web programming tutorial
welookups

delete 29 August 2018 at 20:04



sentiment_satisfied Emoticon