diff --git a/demo/03/src/main/java/pl/amu/edu/demo/primes/UglyImperativePrimes.java b/demo/03/src/main/java/pl/amu/edu/demo/primes/UglyImperativePrimes.java new file mode 100644 index 0000000..55e07ce --- /dev/null +++ b/demo/03/src/main/java/pl/amu/edu/demo/primes/UglyImperativePrimes.java @@ -0,0 +1,32 @@ +package pl.amu.edu.demo.primes; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class UglyImperativePrimes { + + public static void main(String[] args) { + new UglyImperativePrimes().printPrimes(); + } + + public void printPrimes() { + for (int i = 0; i < 121; i++) { + if (isPrime(i)) { + System.out.printf("%d is prime\n", i); + } + } + } + + private boolean isPrime(int number) { + if (number <= 0) { + return false; + } + for (int i = 2; i <= (int) Math.sqrt(number); i++) { + if (number % i == 0) { + return false; + } + } + return true; + } + +}