Pankaj-Str / JAVA-SE-Tutorial-codeswithpankaj

Pankaj-Str's GitHub, 'JAVA-SE-Tutorial-codeswithpankaj,' is a concise compendium of Java SE tutorials. Ideal for developers and learners, it offers clear and insightful code snippets, providing an efficient pathway to enhance Java programming skills. A valuable resource for mastering essential concepts
https://codeswithpankaj.com
32 stars 15 forks source link

Java Program to Find the Largest Element in an Array ? #5

Open Pankaj-Str opened 11 months ago

ghost commented 11 months ago

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);
}

}

Riddhi-Codes7 commented 1 month ago

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); } }

shreyasssdats commented 1 month ago
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);
    }
}
krishna-1284 commented 1 month ago

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);
}

}