exercicio 15
commit
5da520b765
|
|
@ -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>nifs</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.nifs.Nifs</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mycompany.nifs;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author 250406
|
||||||
|
*/
|
||||||
|
public class Nifs {
|
||||||
|
|
||||||
|
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("Invalido");
|
||||||
|
}
|
||||||
|
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("Valido");
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
System.out.println("Invalido");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue