Created
September 21, 2024 03:28
-
-
Save cristofersousa/76ec477a8d3a3d64678c5df7b63fccb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Scanner scanner = new Scanner(System.in); | |
| // Solicita ao usuário que insira um número | |
| System.out.print("Digite um número: "); | |
| int numero = scanner.nextInt(); | |
| // Verifica se o número é primo | |
| boolean ehPrimo = true; | |
| if (numero < 2) { | |
| ehPrimo = false; | |
| } else { | |
| for (int i = 2; i < numero; i++) { | |
| if (numero % i == 0) { | |
| ehPrimo = false; | |
| break; | |
| } | |
| } | |
| } | |
| // Exibe o resultado | |
| if (ehPrimo) { | |
| System.out.println(numero + " é um número primo."); | |
| } else { | |
| System.out.println(numero + " não é um número primo."); | |
| } | |
| scanner.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment