Write a Java program to find the maximum element in an array.

Suman Barik
0

 public class MyClass {

    public static void main(String args[]) {

      // Practice Problem 6

        int [] arr = {1, 2100, - 3, 455, 5, 34, 67};

        int max = Integer.MIN_VALUE;

        for(int e: arr){

            if(e>max){

                max = e;

            }

        }

        System.out.println("the value of the maximum element in this array is: "+ max);

        System.out.println(Integer.MIN_VALUE);

        System.out.println(Integer.MAX_VALUE);

    }

}


//output - 

// the value of the maximum element in this array is: 2100

// -2147483648

// 2147483647


Post a Comment

0Comments
Post a Comment (0)