| about | help | code help+videos | done | prefs |
public int getLastElement2(int[] nums)
public String getLastElement2(String[] words) {
String last = words[3];
return last;
}
If, however, the list can be ANY size, use an expression.
public String getLastElement2(String[] words) {
int len = words.length;
String last = words[len-1];
return last;
}
getLastElement2(["red", "green", "blue", "gold"]) → "gold" getLastElement2(["a", "b", "c", "d"]) → "d" getLastElement2(["w", "x", "y", "z"]) → "z" ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 1
Copyright Nick Parlante 2017 - privacy