JAVA-SE-Tutorial-codeswithpankaj icon indicating copy to clipboard operation
JAVA-SE-Tutorial-codeswithpankaj copied to clipboard

Java Program to Find the Largest Element in an Array ?

Open Pankaj-Str opened this issue 2 years ago • 4 comments
trafficstars

Pankaj-Str avatar Sep 30 '23 13:09 Pankaj-Str

public class main { public static void main(String[] args) { int[] arr = {10, 5, 20, 8, 15};

    int max = arr[0];

    for (int i = 1; i < arr.length; i++) {
        if (arr[i] > max) {
            max = arr[i];
        }
    }
    System.out.println("The largest element in the array is: " + max);
}

}

ghost avatar Oct 06 '23 03:10 ghost

public class LargestElement{

public static void main(String[] args) { double[] arrays = {45.8, 1000.0, -90.3, -1000.0, 200.9}; double largest = arrays[0];

 for (int i=0; i< arrays.length; i++){
  if ( largest < arrays[i])
  {
    largest = arrays[i];
   }

} System.out.println("Largest number in the Array is: " +largest); } }

Riddhi-Codes7 avatar Jul 19 '24 06:07 Riddhi-Codes7

public class largestelement{
    public static void main(String[] args){
        int[] array ={15,89,8,26,33};

        int max= array[0];

        for(int i=1;i<array.length;i++){
            if(array[i]>max){
                max=array[i];
            }
        }
        System.out.println("The largest element in the array is: "+max);
    }
}

shreyasssdats avatar Jul 24 '24 16:07 shreyasssdats

public class Main { public static void main(String[] args) {

    int[] numbers = {10, 25, 50, 5, 35, 75};
    int max = numbers[0];

    for (int i = 1; i < numbers.length; i++) {
        if (numbers[i] > max) {
            max = numbers[i];
        }
    }
    System.out.println("The largest element in the array is: " + max);
}

}

krishna-1284 avatar Aug 09 '24 17:08 krishna-1284