exercicios do teste
parent
9535ba6c73
commit
ef3ac35501
|
|
@ -174,40 +174,87 @@ public class Mavenproject29 {
|
|||
//e. Se o resto for 0 (zero) ou 1 (um) o dígito de controlo será 0 (zero);
|
||||
//f. Se for outro qualquer algarismo X, o dígito de controlo será o resultado da subtracção 11 - X.
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
// 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");
|
||||
// }
|
||||
// }
|
||||
|
||||
// for(int i = 50; i < 50001; i++){
|
||||
// System.out.println(i);
|
||||
// }
|
||||
// Scanner scanner = new Scanner(System.in);
|
||||
// System.out.println("Introduza um número positivo");
|
||||
// int numero1 = scanner.nextInt();
|
||||
// while(numero1 < 0){
|
||||
// System.out.println("O número tem que ser positivo");
|
||||
// numero1 = scanner.nextInt();
|
||||
// }
|
||||
// System.out.println("Introduza um número positivo");
|
||||
// int numero2 = scanner.nextInt();
|
||||
// while(numero2 < 0){
|
||||
// System.out.println("O número tem que ser positivo");
|
||||
// numero2 = scanner.nextInt();
|
||||
// }
|
||||
//
|
||||
// if (numero1 > numero2) {
|
||||
// for(int i = numero2; i <= numero1; i++){
|
||||
// if(i % 2 == 0){
|
||||
// System.out.println(i);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// for(int i = numero1; i <= numero2; i++){
|
||||
// if(i % 2 == 0){
|
||||
// System.out.println(i);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
double soma = 0;
|
||||
double maiorFatura = 0;
|
||||
int mes = 0;
|
||||
for (int i = 0; i < 12; i++){
|
||||
System.out.println("Introduza o valor da fatura " + (i + 1));
|
||||
double valor = scanner.nextDouble();
|
||||
soma += valor;
|
||||
if(valor > maiorFatura){
|
||||
maiorFatura = valor;
|
||||
mes = i + 1;
|
||||
}
|
||||
}
|
||||
System.out.println("A soma das faturas é " + soma);
|
||||
System.out.println("O mês com a maior fatura foi " + mes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue