adicionei comentários

master
250401 2025-11-18 11:40:34 +00:00
commit e24b994e3b
2 changed files with 72 additions and 0 deletions

13
pom.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>Ex1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>24</maven.compiler.release>
<exec.mainClass>com.mycompany.ex1.Ex1</exec.mainClass>
</properties>
</project>

View File

@ -0,0 +1,59 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.mycompany.ex1;
import java.util.Scanner;
/**
*
* @author 250401
*/
public class Ex1 {
// public static void main(String[] args) {
// Scanner scanner = new Scanner(System.in);
// double soma = 0;
// int meses = 12;
// for (int i = 1; i <= meses; i++) {
// System.out.print("Valor da fatura do mês " + i + ": ");
// double valor = scanner.nextDouble();
// soma = soma + valor;
// }
// double media = soma / meses;
// System.out.println("A média das faturas é: " + media);
// }
// public static void main(String[] args) {
// Scanner scanner = new Scanner(System.in);
// //pedir a introdução de um numero ao utilizador
// System.out.println("Introduza um número positivo");
// int numero = scanner.nextInt();
// //validar o número. Voltar a pedir sempre que for negativo
// while(numero <= 0){
// System.out.println("Número invalido. Introduza novamente");
// numero = scanner.nextInt();
// }
// //percorre todos os números entre 0 e o número definido
// //verific se cada um dos número é impar e mostra o que forem
// for(int i = 0; i < numero; i++){
// if(i % 2 != 0){
// System.out.println(i);
// }
// }
// }
public static void main(String[] args) {
for(int i = 2; i <= 1000; i++){
boolean primo = true;
for(int j = 2; j < i ; j++){
if(i % j == 0){
primo = false;
break;
}
}
if(primo){
System.out.println(i);
}
}
}
}