KnowledgeBoat Logo

Computer Applications

Write a program to print all the prime numbers between 1 and 100.

Java

Java Iterative Stmts

48 Likes

Answer

public class KboatPrime
{
    public static void main(String args[]) {
        for (int i = 1; i <= 100; i++) {
            int c = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0)
                    c++;
            }
            if (c == 2)
                System.out.println(i);
        }
    }
}

Output

BlueJ output of Write a program to print all the prime numbers between 1 and 100.

Answered By

21 Likes


Related Questions