THINK FIRST·CODE LATER

← All labs

Prime numbers

Problem

Write a class Primes with a method

public static boolean isPrime(int n)

that returns true when n is a prime number (1 and every number below it are not prime).

The main method reads an integer n and prints all prime numbers from 2 to n, separated by one space, on a single line, after the text Primes: . For n = 10 the output is:

Primes: 2 3 5 7

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.