Advertisement
cesarnascimento

Untitled

Feb 23rd, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. package questao2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Validar {
  6.  
  7.     public void Validar() {
  8.  
  9.         Scanner sc = new Scanner(System.in);
  10.  
  11.         System.out.println("Digite o seu CPF (11 Digítos)");
  12.         String cpf = sc.next();
  13.  
  14.         if (cpf.length() < 11) {
  15.             System.out.println("CPF Inválido");
  16.         } else {
  17.             System.out.println("CPF Válido");
  18.             System.out.println(cpf.substring(0, 3) + "." + cpf.substring(3, 6) + "." + cpf.substring(6, 9) + "-"
  19.                     + cpf.substring(9, 11));
  20.         }
  21.  
  22.     }
  23.  
  24.     public void ValidarCelular() {
  25.         Scanner sc = new Scanner(System.in);
  26.  
  27.         System.out.println("Digite o seu Telefone (11 Digítos)");
  28.         String celular = sc.next();
  29.  
  30.         if (celular.length() < 11) {
  31.             System.out.println("Numero de Telefone Inválido");
  32.         } else {
  33.             System.out.println("Número Válido");
  34.             System.out.println("(" + celular.substring(0, 2) + ") " + celular.substring(2, 3) + " "
  35.                     + celular.substring(3, 7) + "-" + celular.substring(7, 11));
  36.         }
  37.  
  38.  
  39.     }
  40.  
  41.     public void ValidarCEP() {
  42.  
  43.         Scanner sc = new Scanner(System.in);
  44.  
  45.         System.out.println("Digite o CEP");
  46.         String cep = sc.next();
  47.  
  48.         if (cep.length() < 8) {
  49.             System.out.println("CEP Inválido");
  50.         } else {
  51.             System.out.println("CEP Válido");
  52.             System.out.println(cep.substring(0, 6) + "-" + cep.substring(6, 8));
  53.         }
  54.  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement