id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

srp4379@lausd.net 1-arraybasics > getLastElement1
prev  |  next  |  chance

public int getLastElement1(int[] list)

If the arrays you're testing all have different lengths,
then you have to access the last element
by using an expression for the index/position:
list[len-1].

public int getLastElement(int[] numberList) {
  int len = numberList.length;
  int last = numberList[len-1];
  return last;
}

getLastElement1([1, 2, 3, 4, 5]) → 5
getLastElement1([5, 10, 15, 20]) → 20
getLastElement1([3, 6, 9]) → 9

...Save, Compile, Run (ctrl-enter)

public int getLastElement1(int[] numberList) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 1

Copyright Nick Parlante 2017 - privacy