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

Java program to find the largest element in array的更多相关文章

  1. Java for LeetCode 215 Kth Largest Element in an Array

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  2. LeetCode Kth Largest Element in an Array

    原题链接在这里:https://leetcode.com/problems/kth-largest-element-in-an-array/ 题目: Find the kth largest elem ...

  3. Kth Largest Element in an Array 解答

    Question Find the kth largest element in an unsorted array. Note that it is the kth largest element ...

  4. Lintcode: Kth Largest Element 解题报告

    Kth Largest Element Find K-th largest element in an array. Note You can swap elements in the array E ...

  5. LeetCode赛题515----Find Largest Element in Each Row

    问题描述 You need to find the largest element in each row of a Binary Tree. Example: Input: 1 / \ 2 3 / ...

  6. 【leetcode】215. Kth Largest Element in an Array

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  7. Kth Largest Element in a Stream

    Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...

  8. 堆排序 && Kth Largest Element in an Array

    堆排序 堆节点的访问 通常堆是通过一维数组来实现的.在数组起始位置为0的情形中: 父节点i的左子节点在位置(2*i+1); 父节点i的右子节点在位置(2*i+2); 子节点i的父节点在位置floor( ...

  9. [LeetCode] Kth Largest Element in an Array 数组中第k大的数字

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

随机推荐

  1. 【idea】断点调试时查看所有变量和静态变量

    转载至博客:https://blog.csdn.net/qq32933432/article/details/86672341 缘起 笔者在进行HashMap原理探索的时候需要在IntelliJ ID ...

  2. https://zhuanlan.zhihu.com/p/32553477

    科普:QUIC协议原理分析  

  3. mysql - ERROR 1114 (HY000): The table is full

    mysql - ERROR 1114 (HY000): The table is full - Stack Overflowhttps://stackoverflow.com/questions/73 ...

  4. Python3入门(十三)——常用内置模块之时间日期模块datatime

    1.日期时间模块——datatime //其他模块例如time.calender等模块暂不展开 (1)获取当前时间:datatime.now(): from datetime import datet ...

  5. Source Insight 4.0配置格式化工具AStyle.exe

    Source Insight 4.0配置格式化工具AStyle.exe 摘自:https://blog.csdn.net/u012156133/article/details/81566871 1. ...

  6. 教孩子学编程 Python

    教孩子学编程   Python 目录 第1 章 Python 基础:认识环境 111 认识Python 312 用Python 编写程序 513 运行Python 程序 514 本章小结 615 编程 ...

  7. 海康威视实时预览回调PS流用EasyRTMP向RTMP服务器推流中视频数据处理的代码

    在上一篇方案<EasyRTMP结合海康HCNetSDK获取海康摄像机H.264实时流并转化成为RTMP直播推流(附源码)>我们介绍了将海康安防摄像机进行互联网直播的整体方案流程,其中有一个 ...

  8. 【DeepCTR】

    DeepFM: https://www.jianshu.com/p/6f1c2643d31b CCPM,FGCNN: https://cloud.tencent.com/developer/artic ...

  9. docker 下mysql 和postgresql 数据库的搭建以及数据文件的迁移和备份

    service docker start - docker 启动 service docker stop - docker 关闭 1.docker 镜像创建—使用的默认镜像有数据卷 docker pu ...

  10. 07点睛Spring MVC4.1-ContentNegotiatingViewResolver

    转发地址:https://www.iteye.com/blog/wiselyman-2214965 7.1 ContentNegotiatingViewResolver ContentNegotiat ...