Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Main {
- public static void main(String[] args) {
- String nome = "SAMUEL CARLOS PEDRO LUCAS OLIVERA TORRES DA COSTA LEMOS";
- String resultado = retornaNome(nome);
- System.out.println(resultado);
- }
- public static String retornaNome(String nome){
- String resultado = null;
- String array[] = nome.split(" ");
- char[] bloco;
- resultado = array[0] + " ";
- //resultado += " "+ array[array.length-1];
- for(int i=1; i<array.length-1; i++){
- bloco = array[i].toCharArray();
- if(array[i].length() > 2){
- resultado += bloco[0] + ". ";
- }
- else{
- resultado += array[i] + " ";
- }
- System.out.println(array[i].length());
- }
- resultado += array[array.length-1];
- if(resultado.length() > 30){
- System.out.println(resultado.length());
- }
- return resultado;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement