zoukankan      html  css  js  c++  java
  • Java program to find the largest element in array

    Java program to find the largest element in array

    Given an array of numbers, write a java program to find the largest element in the given array.

    Example:

    int[] a = {1, 5, 3, 9, 2, 8, 2} Largest Element: 9

    Java 代码

    public class LargestElementInArray {
        public static void findLargestElement(int[] a) {
            if (a == null || a.length == 0) {
                return;
            }
            int largest_element = a[0];
            for (int i = 1; i < a.length; i++) {
                if (a[i] > largest_element) {
                    largest_element = a[i];
                }
            }
            System.out.println("Largest element in array: " + largest_element);
        }
    
        public static void main(String[] args) {
            int[] a = {1, 5, 3, 9, 2, 8, 2};
            findLargestElement(a);
        }
    }
    
  • 相关阅读:
    hadoop yarn日志分离
    hadoop优化
    hive UDF
    hadoophttpfs
    spark编译
    spark feature
    python
    python 装饰器
    HTML特殊转义字符列表
    博客园数据统计
  • 原文地址:https://www.cnblogs.com/hgnulb/p/10896640.html
Copyright © 2011-2022 走看看