Advertisement
JVFabia

Clase 1 Ejercicio Palabras

Sep 23rd, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package org.forge;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.     // write your code here
  11.  
  12.         List<String> palabras = new ArrayList<String>();
  13.         Scanner in = new Scanner(System.in);
  14.  
  15.         while (true){
  16.             String nombre = "";
  17.             System.out.println("Ingrese un nombre");
  18.             nombre = in.nextLine().toUpperCase();
  19.  
  20.             if (nombre.equals("STOP") ){
  21.                 break;
  22.             }
  23.  
  24.             palabras.add(nombre);
  25.         }
  26.  
  27.         String temp = "";
  28.         for (int i = 0; i <= palabras.size() -1 ; i++ ){
  29.             if (temp != "" ) {
  30.                 if (temp.length() < palabras.get(i).length()) {
  31.                     temp = palabras.get(i);
  32.                 }
  33.                 //System.out.println("El nombre del indice " + i + " es "+ palabras.get(i) + " y es de tamaño " + palabras.get(i).length());
  34.             }else{
  35.                 temp = palabras.get(i);
  36.             }
  37.         }
  38.         System.out.println(" La palabra con mas caracteres es " + temp);
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement