首页 > 编程语言 > 详细

寻找数组中最大值

时间:2015-03-11 14:52:46      阅读:246      评论:0      收藏:0      [点我收藏+]
/**
 * 对于给定整数数组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);
}
}

寻找数组中最大值

原文:http://blog.csdn.net/a736933735/article/details/44197571

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!