Java Array Max Value max(int[] in, int x1, int x2)

Here you can find the source of max(int[] in, int x1, int x2)

Description

max

License

Open Source License

Declaration

static public int max(int[] in, int x1, int x2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static public int max(int[] in, int x1, int x2) {

        int maxval = 0;

        if (in != null && x1 >= 0) {

            for (int i = x1; i < Math.min(in.length, x2); i++) {

                maxval = Math.max(in[i], maxval);

            }//w  w w  .jav  a 2s.  c o m
        } else {
            System.out.println("erreur dimensionnement maxvalue");
        }
        return maxval;

    }

    static public double max(double[] in, int x1, int x2) {

        double maxval = 0;

        if (in != null && x1 >= 0) {

            for (int i = x1; i < Math.min(in.length, x2); i++) {

                maxval = Math.max(in[i], maxval);

            }
        } else {
            System.out.println("erreur dimensionnement maxvalue");
        }
        return maxval;

    }

    static public int max(int[] in) {

        int maxval = 0;

        if (in != null) {

            for (int i = 0; i < in.length; i++) {

                maxval = Math.max(in[i], maxval);

            }
        }

        return maxval;

    }

    static public int min(int[] in, int x1, int x2) {

        int minval = 999999;

        if (in != null && x1 >= 0) {

            for (int i = x1; i < Math.min(in.length, x2); i++) {

                if (in[i] != 0)
                    minval = Math.min(in[i], minval);

            }
        }

        return minval;

    }

    static public int min(int[] in) {

        int minval = 999999;

        if (in != null) {

            for (int i = 0; i < in.length; i++) {

                if (in[i] != 0)
                    minval = Math.min(in[i], minval);

            }
        }

        return minval;

    }
}

Related

  1. max(int[] array)
  2. max(int[] as)
  3. max(int[] data)
  4. max(int[] elements)
  5. max(int[] ids)
  6. max(int[] list)
  7. max(int[] nums)
  8. max(int[] t)
  9. max(int[] vals, int max)