Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: finalizando o desafio 6 em java #373

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions challenges/6-numeros-primos/java/willy-r/PrimeNumbers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class PrimeNumbers {
public static void main(String[] args) {
int input = Integer.parseInt(args[0]);
System.out.println(isPrime(input));
}

private static boolean isPrime(int number) {
if (number <= 1) {
return false;
}
if (number == 2 || number == 3) {
return true; // Special cases.
}
if (number % 2 == 0 || number % 3 == 0) {
return false;
}
for (int i = 5; i * i <= number; i += 6) { // Starts at 5 because 4 isn't prime.
// Check for prime by testing divisors up to the square root of the number.
if (number % i == 0 || number % (i + 2) == 0) {
return false;
}
}
return true;
}
}
22 changes: 22 additions & 0 deletions challenges/6-numeros-primos/java/willy-r/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Submissão de Exercicio

**Exercicio:** 6 - Números Primos

**Nickname:** willy-r

**Nível Técnico:** Pleno

**Empresa:** Mutant

**Twitter**: https://twitter.com/lliw_r

**Dificuldade de Resolução:** Média

**Comentários:** Essa foi um pouco mais complicada mas dando uma pesquisada ficou mais de boa ir montando o algorítimo.

**Como rodar o desafio**:

Dentro do diretório do projeto, utilize o comando abaixo:
```bash
java PrimeNumbers.java 2
```