- public class Maxmin {
- public static void main(String[] args) {
- int[] y= {0,9,4,8,2,12,444,5,-1,-22,45};
- System.out.println(m(y));
- System.out.println(mm(y));
-
- }
- public static int m(int[] p){
- int max=0;
- for (int i=0;i<p.length;i++){
- if(p[i]>=max){
- max=p[i];
- }
- }
- return max;
- }
- public static int mm(int[] p){
- int min=p[0];
- for (int i=1;i<p.length;i++){
- if(p[i]<=min){
- min=p[i];
- }
- }
- return min;
- }
-
- }
复制代码 |