92/93求出数组中最大的值和数组元素反转

求出数组中的最大值

举例

 

 

    public static void main(String[] args) {
        int [] array = {5,15,30,20,10000,30,35};
        int max = array[0];
        for (int i = 1; i <array.length ; i++) {
            if (array[i]>max){
                max = array[i];
            }
        }
        System.out.println("最大值"+max);
    }
}

运行结果

数组元素的反转

package com.fgy.demo;

/**
 * 数组元素反转
 */
public class demo05 {
    public static void main(String[] args) {
        int[] arr = {10, 20, 30, 40, 50};
        System.out.print("数组反转前:");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "   ");
        }

        System.out.println();
        for(int min = 0, max = arr.length - 1; min < max; min++, max--) {
            int temp = arr[min];
            arr[min] = arr[max];
            arr[max] = temp;
        }

        System.out.print("数组反转后:");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "   ");
        }
    }
}
posted @ 2022-07-03 20:07  ja不会va  阅读(26)  评论(0)    收藏  举报