Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Pankaj-Str opened this issue Sep 30, 2023 · 4 comments
Open

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

Pankaj-Str opened this issue Sep 30, 2023 · 4 comments
Labels
question Further information is requested

Comments

@Pankaj-Str
Copy link
Owner

No description provided.

@ghost
Copy link

ghost commented Oct 6, 2023

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
Copy link

Riddhi-Codes7 commented Jul 19, 2024

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

@Pankaj-Str Pankaj-Str added the question Further information is requested label Jul 20, 2024
@shreyasssdats
Copy link

shreyasssdats commented Jul 24, 2024

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
Copy link

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
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants