Created
October 24, 2015 19:15
-
-
Save edinak1/bdf06b4304f493e5411c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package masiv; | |
| public class LastElement { | |
| public static void main(String[] args) { | |
| int [] data={1,10,5,7,6}; | |
| int [] data1={0}; | |
| int [] data2={}; | |
| int [] data3={0,0,15,25,16}; | |
| int [] data4={-3,25,2}; | |
| System.out.println(getLast(data)); | |
| System.out.println(getLast(data1)); | |
| System.out.println(getLast(data2)); | |
| System.out.println(getLast(data3)); | |
| System.out.println(getLast(data4)); | |
| } | |
| static int getLast(int[] data) | |
| { | |
| if(data==null || data.length==0) | |
| return -1; | |
| return data[data.length-1]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment