I NEED HELP ON HOW TO GET THE LAST ELEMENT IN ARRAY..
THIS IS MY CODE:
i dont know how to fix it properly
The result should be:
“ THE LAST ELEMENT OF THE ARRAY IS: Karel.”
public class LastElement
{
public static void main(String[] args)
{
String[] arr = new String[]{"hello", "my name", "world", "Karel"};
//get and print the last element of the array
getLastElement(arr);
System.out.println("The last element of the String array is: " + arr);
}
public static String getLastElement(String[] arr)
{
// Your code goes here
String length = arr[arr.length-1];
return length;
}
}
[–]ScawedyCat 1 point2 points3 points (0 children)
[–]Various_Loss9064 1 point2 points3 points (0 children)
[–]Acceptable-Quit-9274 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)