Skip to content

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

Open
@Pankaj-Str

Description

@Pankaj-Str
No description provided.

Activity

ghost

ghost commented on Oct 6, 2023

@ghost

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

Riddhi-Codes7 commented on Jul 19, 2024

@Riddhi-Codes7

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

shreyasssdats commented on Jul 24, 2024

@shreyasssdats
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

krishna-1284 commented on Aug 9, 2024

@krishna-1284

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Pankaj-Str@shreyasssdats@krishna-1284@Riddhi-Codes7

        Issue actions

          Java Program to Find the Largest Element in an Array ? · Issue #5 · Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj