From 8c4fff83a6e0a5ecee27e40390db0252b3e40e54 Mon Sep 17 00:00:00 2001 From: 250408 <250408@localhost> Date: Thu, 27 Nov 2025 09:13:57 +0000 Subject: [PATCH] Exercicios Novos --- .../mavenproject1/Mavenproject1.java | 165 ++++++++++++++++-- 1 file changed, 149 insertions(+), 16 deletions(-) diff --git a/mavenproject1/src/main/java/com/mycompany/mavenproject1/Mavenproject1.java b/mavenproject1/src/main/java/com/mycompany/mavenproject1/Mavenproject1.java index 005393c..d6f34c6 100644 --- a/mavenproject1/src/main/java/com/mycompany/mavenproject1/Mavenproject1.java +++ b/mavenproject1/src/main/java/com/mycompany/mavenproject1/Mavenproject1.java @@ -4,6 +4,9 @@ package com.mycompany.mavenproject1; +import static java.lang.Math.random; +import static java.lang.StrictMath.random; +import java.util.Random; import java.util.Scanner; /** @@ -81,22 +84,152 @@ public class Mavenproject1 { // for(int i = 10; i > -1; i--){ // System.out.println(i); // } - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); +// public static void main(String[] args) { +// Scanner scanner = new Scanner(System.in) +//// System.out.println("NIF?"); +// String nif = scanner.nextLine(); +// if(nif.length()!= 9){ +// System.out.println("inválido"); +// } +// else{ +// int multiplicador = 9; +// int soma = 0; +// for(int i = 0; i < nif.length()-1 ; i++){ +// int digito= Integer.parseInt(String.valueOf(nif.charAt(i))); +// int multiplicacao = digito * multiplicador; +// soma += multiplicacao; +// multiplicador--; +// } +// int resto = soma % 11; +// int digitoControlo; +// if(resto == 0 || resto == 1){ +// digitoControlo = 0; +// } +// else{ +// digitoControlo = 11 - resto; +// } +// int nonoDigito = Integer.parseInt(String.valueOf(nif.charAt(8))); +// if(nonoDigito == digitoControlo){ +// System.out.println("Válido"); +// } +// else{ +// System.out.println("Inválido"); +// } +// +// } +// +// } +//} +// + +// 1. Escreva um programa em Java que mostre no ecrã todos os números entre 50 e 50000. +// public static void main(String[] args) { +// Scanner scanner = new Scanner(System.in); +// for(int i = 50; i <= 50000; i++){ +// System.out.println(i); +// } +// } +// +// } + +// 2. Escreva um programa em Java que solicite ao utilizador a introdução de dois números +// positivos (validar a entrada). O programa deve mostrar todos os números pares entre +// esses dois números, incluindo os próprios, se forem pares + +// public static void main(String[] args) { +// Scanner scanner = new Scanner(System.in); +// System.out.println("Introduza um numero positivos"); +// int n1 = scanner.nextInt(); +// while(n1 < 0){ +// System.out.println("O numero tem que ser positivo"); +// numero1 = scanner.nextInt(); +// } +// System.out.println("introduza o segundo numero positivo"); +// int n2 = scanner.nextInt(); +// while(n2 < 0){ +// System.out.println("O numero tem que ser positivo"); +// numero2 = scanner.nextInt(); +// } +// for (int i = n1; i <= n2; i++) { +// if (i % 2 == 0) { +// System.out.print(i); +// } +// } +// } +// else{ +// for (int i = n2; i <= n1; i++) { +//// if (i % 2 == 0) { +//} +//} +// 3. Desenvolva um programa em Java que solicite ao utilizador os valores das faturas de um +// ano (12 meses). O programa deve calcular a soma total dessas faturas e indicar qual mês +// teve o maior valor. + +// public static void main(String[] args) { +// Scanner scanner = new Scanner(System.in); +// double soma = 0; +// double maiorFator = 0; +// int mesMaior = 0; +// for (int mes = 1; mes <= 12; mes++) { +// System.out.print("Introduza o valor da fatura do mês " + mes + ": "); +// double valor = scanner.nextDouble(); +// soma += valor; +// if (mes == 1 || valor > maiorFator) { +// maiorFatura = valor; +// mesMaior = i; +// } +// } +// System.out.println("Soma total das faturas é " + soma); +// System.out.println("O mês com maior valor é o mês " + mesMaior); +// } +//} +//4. Escreva um programa em Java que solicite ao utilizador a introdução de um número inteiro +//positivo. O programa deve gerar e mostrar a tabela de multiplicação desse número, de 1 a +//10 + +// public static void main(String[] args) { +// Scanner scanner = new Scanner(System.in); +// System.out.print("Introduza um número inteiro positivo: "); +// int numero = scanner.nextInt(); +// +// System.out.println("Tabuada do " + numero + ":"); +// +// int i = 1; +// for (int j = 0;j <= 10; j++) { +// System.out.println(numero + " x " + i + " = " + (numero * i)); +// i++; +// } +// +// } +// } + + +//5. Crie um programa em Java que gere e imprima uma matriz de 5x5 com valores aleatórios +//entre 1 e 100. Utilize dois ciclos for para percorrer e preencher a matriz. Depois de +//preenchida, mostre todos os valores da matriz no ecrã. Nota: para se gerar um número +//aleatório entre 0 e 100 utiliza-se a seguinte instrução: +//int numeroAleatorio = new Random().nextInt(100) + +// public static void main(String[] args) { +// Scanner scanner = new Scanner(System.in); +// Random random = new Random(); +// for (int j = 0; j < 5; j++) +// { +// for (int i = 0; i < 5; i++) +// { +// int numeroAleatorio = random.nextInt(99); +// System.out.print(numeroAleatorio + "\t"); +// { +// System.out.println(); +// } +// } + +public static void main(String[] args) { - - System.out.println("NIF?"); - String nif = scanner.nextLine(); - if(nif.length()!= 9){ - System.out.println("inválido"); - } - else{ - int multiplicador = 9; - for(int i = 0; i < nif.length()-1 ; i++){ - int digito= Integer.parseInt(String.valueOf(nif.charAt(i))); - - } - } +} } -} \ No newline at end of file + + + + \ No newline at end of file