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

largest element in an array #12

Open krishna-1284 opened 1 month ago

krishna-1284 commented 1 month ago

public class Main {

public static void main(String[] args) {
    int[] numbers = {10, 25, 50, 5, 35, 75, 20};

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

}