首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

怎么取一组数据中的最大值(数组、集合)

2012-10-07 
如何取一组数据中的最大值(数组、集合)??public static void main(String[] args){??????? ListInteger l

如何取一组数据中的最大值(数组、集合)

?

?

public static void main(String[] args){

?

?????? List<Integer> list = new ArrayList<Integer>();

?

???????list.add(8);

?????? list.add(5);

?????? list.add(7);

?????? list.add(2);

?????? list.add(9);

?

?????? int max = 0;

?????? for(int i=0;i<list.size();i++){

?

???????????? if(list.get(i) >max)

???????????????????

?????????????????? max = list.get(i);

???? }

?????? System.out.println("max的值为:" +max);

}

?

??? 输出:max的值为:9

?

数组类似。

热点排行