commit inicial
parent
d6064d40c5
commit
546b2daced
|
|
@ -11,6 +11,16 @@ import java.util.Scanner;
|
|||
* @author 250410
|
||||
*/
|
||||
public class Exercicios {
|
||||
|
||||
|
||||
|
||||
/***************************************************
|
||||
* *
|
||||
* Exercicio *
|
||||
* *
|
||||
/******************************+********************
|
||||
|
||||
*/
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// Scanner scanner = new Scanner(System.in);
|
||||
|
|
@ -59,32 +69,150 @@ public class Exercicios {
|
|||
// nomeDaString.lenght() - retorna o tamanho da string
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("Introduza o seu nome");
|
||||
String nome = scanner.nextLine();
|
||||
|
||||
System.out.println("A quantidade de carcteres é " + nome.length());
|
||||
System.out.println("Em maisculas: " + nome.toUpperCase());
|
||||
System.out.println("Em minusculas: " + nome.toLowerCase());
|
||||
System.out.println("Contem campos? " + nome.contains("campos"));
|
||||
System.out.println("O primeiro carcter é " + nome.charAt(0));
|
||||
System.out.println("O carcter do meio é " + nome.charAt(nome.length() / 2));
|
||||
int contador = 0;
|
||||
for(int i = 0; i < nome.length() ; i++){
|
||||
if(nome.charAt(i) == 'a'){
|
||||
contador++;
|
||||
}
|
||||
}
|
||||
System.out.println("O nome tem " + contador + " a's");
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************
|
||||
* *
|
||||
* Exercicio *
|
||||
* *
|
||||
/******************************+********************
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// Scanner scanner = new Scanner(System.in);
|
||||
// System.out.println("Introduza o seu nome");
|
||||
// String nome = scanner.nextLine();
|
||||
//
|
||||
// System.out.println("A quantidade de carcteres é " + nome.length());
|
||||
// System.out.println("Em maisculas: " + nome.toUpperCase());
|
||||
// System.out.println("Em minusculas: " + nome.toLowerCase());
|
||||
// System.out.println("Contem campos? " + nome.contains("campos"));
|
||||
// System.out.println("O primeiro carcter é " + nome.charAt(0));
|
||||
// System.out.println("O carcter do meio é " + nome.charAt(nome.length() / 2));
|
||||
// int contador = 0;
|
||||
// for(int i = 0; i < nome.length() ; i++){
|
||||
// if(nome.charAt(i) == 'a'){
|
||||
// contador++;
|
||||
// }
|
||||
// }
|
||||
// System.out.println("O nome tem " + contador + " a's");
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************
|
||||
* *
|
||||
* conversão de dados String *
|
||||
* *
|
||||
/******************************+********************
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// //conversão entre tipos de dados
|
||||
// //conversão de um tipo de dado para a String
|
||||
// String.valeuOf(valorAConverter)
|
||||
// //conversão de String para nt
|
||||
// integer.parseInt(stringAConverter)
|
||||
// //conversão de String para double
|
||||
// Double.parseDouble(stringAConverter)
|
||||
// //conversão de String para float
|
||||
// Float.parseFloat(stringAConverter)
|
||||
// //conversão de String para long
|
||||
// Long.parseLong(stringAConverter)
|
||||
|
||||
/***************************************************
|
||||
* *
|
||||
* Exercicio *
|
||||
* *
|
||||
/******************************+********************
|
||||
|
||||
*/
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// Scanner scanner = new Scanner(System.in);
|
||||
// System.out.println("Introduza um número");
|
||||
// String numero = scanner.nextLine();
|
||||
// int numeroInteiro = Integer.parseInt(numero);
|
||||
// double numeroDouble = Double.parseDouble(numero);
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************
|
||||
* *
|
||||
* Exercicio *
|
||||
* *
|
||||
/******************************+********************
|
||||
|
||||
*/
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// for(int i= 0; i < 11; i++){
|
||||
// System.out.println(i);
|
||||
// }
|
||||
// for(int i= 10; i < 0; i++){
|
||||
// System.out.println(i);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************
|
||||
* *
|
||||
* Exercicio *
|
||||
* *
|
||||
/******************************+********************
|
||||
|
||||
*/
|
||||
|
||||
// Desenvolve um programa, que solicite os 9 dígitos de um nif(deve ser pedido um digito de cada vez). No final, o programa deverá informar se o nif é válido.
|
||||
// a. O NIF tem 9 dígitos, sendo o último o digito de controlo. Para ser calculado o digito de controlo:
|
||||
// b. Multiplique o 8.º dígito por 2, o 7.º dígito por 3, o 6.º dígito por 4, o 5.º dígito por 5, o 4.º dígito por 6, o 3.º dígito por 7, o 2.º dígito por 8 e o 1.º dígito por 9;
|
||||
// c. Some os resultados;
|
||||
// d. Calcule o resto da divisão do número por 11;
|
||||
// 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.
|
||||
|
||||
// a.
|
||||
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;
|
||||
for(int i = 0; i < nif.length(); i++){
|
||||
int digito = Integer.parseInt(String.valueOf(nif.charAt(i)));
|
||||
int multiplicacao = digito * multiplicador;
|
||||
multiplicador--;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue