Exercicio 13 e 14 feitos

master
250408 2025-11-18 11:17:18 +00:00
commit bc922a956e
1 changed files with 74 additions and 0 deletions

View File

@ -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);
}
}
}
}