String[] names = {"Maria", "Juan", "Felippe"};
System.out.print(names[0] + " " + names[1] + " " + names[2]);
String[] words = new String[3];
words[0] = "Java";
words[1] = "Programming";
words[2] = "Language";
System.out.print(words[0] + " " + words[1] + " " + words[2]);
String[] wordArray = new String[3];
for(int i = 0; i < wordArray.length; i++){
System.out.println("Enter word " + (i+1) + ": ");
wordArray[i] = input.next();
}
//uses regular for loop to print all words in wordArray
for(int i = 0; i < wordArray.length; i++){
System.out.print(wordArray[i] + " ")
}
//uses enhanced for loop to print all words in wordArray
for(String w: wordArray){
System.out.print(w + " ");
}
String longestWord = "";
for(int i = 0; i < wordArray.length - 1; i++){
if(wordArray[i].length() > longestWord.length()){
longestWord = wordArray[i];
}
}
System.out.println("The longest word in the array is: " + longestWord);
int longestLengthOfWord = 0;
for(int i = 0; i < wordArray.length; i++){
if(wordArray[i].length() > longestLengthOfWord){
longestLengthOfWord = wordArray[i].length();
}
}
System.out.println("Longest length of word in the array: " + longestLengthOfWord);