From d641c6124f8739892e1797d796041bc137facf91 Mon Sep 17 00:00:00 2001 From: Uiratan Cavalcante Date: Thu, 30 Nov 2023 06:38:43 -0300 Subject: [PATCH] =?UTF-8?q?Solu=C3=A7=C3=A3o=20do=20desafio=2002=20em=20ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desafio-02/uiratan/java/PrimeNumbers.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 desafio-02/uiratan/java/PrimeNumbers.java diff --git a/desafio-02/uiratan/java/PrimeNumbers.java b/desafio-02/uiratan/java/PrimeNumbers.java new file mode 100644 index 000000000..5735b99b5 --- /dev/null +++ b/desafio-02/uiratan/java/PrimeNumbers.java @@ -0,0 +1,23 @@ +public class PrimeNumbers { + public static void main(String[] args) { + int firstNumber = 0; + int lastNumber = 10000; + + int actualNumber = firstNumber; + + while (actualNumber <= lastNumber) { + if (isPrimeNumber(actualNumber)) { + System.out.println(actualNumber); + } + actualNumber++; + } + } + + static boolean isPrimeNumber(int number) { + if (number <= 1) return false; + + for (int i = 2; i <= Math.sqrt(number); i++) if (number % i == 0) return false; + + return true; + } +}