数组中的索引是从0开始算的,那么就简单了,直接读取(数组长度-1)处的元素就是数组中的最后一个数了,代码如下:
public class Test {您好,提问者:
int[] arr = {1,2,3,4,5};
1、直接通过下标来获取
2、下标的值就是当前数组的长度-1,就可以
3、见图
4、见代码:
/**
* 公司 深圳市海枫科技有限公司
* 创建时间 2018年6月22日
* 邮件 [email protected]
*/
package com.itdugu.unit01.test1;
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
String arr[] = {"海枫科技","独孤码农","深圳市海枫科技独孤码农"};
System.out.println("获取数组的最后一个是:"+arr[arr.length-1]);
}
}