A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© MilesMatheson 中级黑马   /  2015-9-11 15:07  /  391 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

遍历二维数组求出最大值和最小值:
  1. package Temp;

  2. public class myInt {

  3.         /**
  4.          * @param args
  5.          */
  6.         public static void main(String[] args) {
  7.                 int[][] arr= {{23,34,87,78},{12,-34,-766,56},{23,54,999,44}};
  8.                 int min = arr[0][0];
  9.                 int max = arr[0][0];
  10.                 for(int[] arrTemp:arr)
  11.                 {
  12.                         for(int i: arrTemp)
  13.                         {
  14.                                 if(i<min)
  15.                                 {
  16.                                         min = i;
  17.                                 }
  18.                                 if(max < i)
  19.                                 {
  20.                                         max = i;
  21.                                 }
  22.                         }
  23.                 }
  24.                
  25.                 System.out.println("Min:"+min);
  26.                 System.out.println("Max:"+max);
  27.         }

  28. }
复制代码

3 个回复

倒序浏览
这位哥们,可以喔
回复 使用道具 举报
这位哥们,可以喔
回复 使用道具 举报
这位哥们,可以喔
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马