Skip to content

Instantly share code, notes, and snippets.

@Yur-ok
Created December 16, 2015 14:08
Show Gist options
  • Save Yur-ok/6a5a05aaae8dd69e797c to your computer and use it in GitHub Desktop.
Save Yur-ok/6a5a05aaae8dd69e797c to your computer and use it in GitHub Desktop.
package Lesson3.KeyPoint1;
/**
* Created by Юрий on 16.12.2015.
*/
public class GetLastIndexOfArray {
public static void main(String[] args) {
int[] arr1 = {1, 10, 5, 7, 6};
int[] arr2 = {0};
int[] arr3 = new int[0];
int[] arr4 = {0, 0, 15, 25, 16};
int[] arr5 = {-3, 25, 2};
System.out.println(getLast(arr1));
System.out.println(getLast(arr2));
System.out.println(getLast(arr3));
System.out.println(getLast(arr4));
System.out.println(getLast(arr5));
}
static int getLast(int[] data) {
int lastIndex = data.length;
if (lastIndex > 0) {
return data[lastIndex - 1];
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment