2

Java Code to display all of the prime numbers between 1 and 60.

Q: Write a Java program that displays all of the prime numbers between 1 and 60.

Solution

class prime
{
    public static void main(String arg[])
    {
        for (int n = 1; n <= 60; n++){
            int count = 0;

            for (int i = 2; i <= n/2; i++){
                if(n%i==0){
                    count++;
                    break;
                }
            }

            if(count==0 && n!=1){
                    System.out.println(n);
             }
         }
    }
}

Discuss this program below.