求数组int a[] = {4,-1,9,10,23},最大值,并得到对应index

2022/2/12 23:48:12

本文主要是介绍求数组int a[] = {4,-1,9,10,23},最大值,并得到对应index,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

//求数组int a[] = {4,-1,9,10,23},最大值,并得到对应index
public class test{
    public static void main(String[] args) {
        int a[] = {4,-1,9,10,23},temp = 0 ,index = 0;
            for (int i = 0; i <= 3;i++){
                if (a[i] < a[i+1]){
                    temp = a[i+1];
                    index = i + 1; 
                }
            }
            System.out.print("该数组最大值 = " + temp + "\n该数组最大值的下标 = " + index);
    };
}

 



这篇关于求数组int a[] = {4,-1,9,10,23},最大值,并得到对应index的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程