commit bc922a956e738a3cfcfcff0de62ccf38ccae180c Author: 250408 <250408@localhost> Date: Tue Nov 18 11:17:18 2025 +0000 Exercicio 13 e 14 feitos diff --git a/src/main/java/com/mycompany/exerciciosfor3/ExerciciosFor3.java b/src/main/java/com/mycompany/exerciciosfor3/ExerciciosFor3.java new file mode 100644 index 0000000..963c669 --- /dev/null +++ b/src/main/java/com/mycompany/exerciciosfor3/ExerciciosFor3.java @@ -0,0 +1,74 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.mycompany.exerciciosfor3; + +import java.util.Scanner; + +/** + * + * @author 250408 + */ +public class ExerciciosFor3 { + + /*********************************************** + * + * Exercicio 12 + * + ************************************************/ +// public static void main(String[] args) { + // Scanner scanner = new Scanner(System.in); + //double soma = scanner.nextDouble(); + // for(int i = 0; i < 12; i++) { + // + //System.out.println("Introduza o valor da fatura "+(1 +1)); + // + // double valor = scanner.nextDouble(); + // + // soma += valor; + // + //} + // + //Double media = soma / 12; + // + //System.out.println("A média das faturas é " + media); + // } + + /*********************************************** + * + * Exercicio 13 + * + ************************************************/ + + // public static void main(String[] args) { + // for (int i = 0; i <= 1000; i++) { + // System.out.println(i); + + //} + + /*********************************************** + * + * Exercicio 14 + * + ************************************************/ + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + 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 inválido. Introduza novamente"); + numero = scanner.nextInt(); + } + //percorre tdos os numeros entre 0 e o numero defenido + //verifica se cada um dos numeros é impar e mostra o que forem + for(int i = 0; i < numero; i++){ + if(i % 2 != 0){ + System.out.println(i); + } + } + + } +}