Advertisement
slemos96

Abreviar nome

Dec 6th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. class Main {
  2.  
  3.   public static void main(String[] args) {
  4.     String nome = "SAMUEL CARLOS PEDRO LUCAS OLIVERA TORRES DA COSTA LEMOS";
  5.     String resultado = retornaNome(nome);
  6.     System.out.println(resultado);
  7.    
  8.   }
  9.  
  10.   public static String retornaNome(String nome){
  11.     String resultado = null;
  12.     String array[] = nome.split(" ");
  13.    
  14.     char[] bloco;
  15.    
  16.     resultado = array[0] + " ";
  17.     //resultado += " "+ array[array.length-1];
  18.    
  19.     for(int i=1; i<array.length-1; i++){
  20.      
  21.       bloco = array[i].toCharArray();
  22.      
  23.       if(array[i].length() > 2){
  24.         resultado += bloco[0] + ". ";
  25.       }
  26.       else{
  27.         resultado += array[i] + " ";
  28.       }
  29.       System.out.println(array[i].length());
  30.     }
  31.     resultado += array[array.length-1];
  32.     if(resultado.length() > 30){
  33.       System.out.println(resultado.length());
  34.     }
  35.     return resultado;
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement