Skip to content

Commit

Permalink
Solução do desafio 02 em java
Browse files Browse the repository at this point in the history
  • Loading branch information
uiratan committed Nov 30, 2023
1 parent af11385 commit d641c61
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions desafio-02/uiratan/java/PrimeNumbers.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit d641c61

Please sign in to comment.