this code is designed to initialise an array C and its values, then print them and print the largest string within the array. i have used an enhanced for loop. the debug showed an error that 'longest name' was not initialised so i added =null to it when declaring the string but the output of the program always prints null now rather than the longest string in the array please help!
package week14;
public class LabArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
int [] A = new int[5];
int [] B = new int[5];
String [] C = {"luke", "elliot", "glenn", "jonny", "jack"};
int [] D = new int[5];
int length = C[1].length();
String longestname;
int nextlength;
for (String name: C){
System.out.println(name);
nextlength = name.length();
System.out.println(name.length());
if (nextlength > length){
length = nextlength;
longestname = name;
}
}
System.out.println("\nthe longest word in the array = " + longestname);
}
}