Advertisement
apez1

Term 1: Lesson 29 - Coding Activity 1

Oct 23rd, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. public class Lesson_29_Activity_One {
  2.  
  3.     public static String [] list = {"high", "every", "nearing", "checking", "food ", "stand", "value", "best", "energy", "add", "grand", "notation", "abducted", "food ", "stand"};
  4.    
  5.     public static void main(String[] args) {
  6.        
  7.         int length[] = new int[list.length];
  8.         int prevlargest = 0;
  9.         String indexoflargest = null;
  10.  
  11.         for(int i = 0; i < list.length; i++) {
  12.            
  13.             length[i] = list[i].length();          
  14.            
  15.             if(length[i] > prevlargest) {
  16.                 prevlargest = length[i];
  17.                 indexoflargest = list[i];
  18.             }
  19.            
  20.            
  21.     }
  22.         System.out.println(indexoflargest);
  23.  
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement