遍历输出且输出数组中最大的值

 1 int myarray[] = new int[]{44,22,301,54,5,88,7,48,9,10};
 2         
 3         //遍历并输出所有的数
 4         for(int x :myarray)
 5         {
 6             System.out.print(x+" ");
 7         }
 8         System.out.println();
 9         //利用foreach来写输出数组中最大的数
10                 int Max = myarray[0];
11                 
12                 for(int x:myarray)
13                 {
14                     if(Max>=x)
15                     {
16                     }
17                     else
18                     {
19                         Max = x;
20                     }
21                 }
22                 System.out.println("这个数组中最大的值是:"+Max);

运行的结果:

原文地址:https://www.cnblogs.com/zhengfengyun/p/5113831.html