寻找数组中最大值

/**
 * 对于给定整数数组a[],寻找其中最大值,并返回下标
 */
import java.util.*;
import java.io.*;


public class 寻找数组中最大值 {


public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[max] < a[j]) {
max = j;
}
}
}
System.out.println(a[max] + " " + max);
}
}

你可能感兴趣的:(蓝桥杯)