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. 重写Dijkstra

    啊我沙雕了,竟然以为DJ的邻接矩阵不用初始化.. #include<bits/stdc++.h> #define R register int using namespace std; / ...

  2. CF1214题解

    D 因为可以用贡献2把起点终点堵掉,所以答案为0/1/2 0/2简单 1:方格可以理解为分层图,考虑每个能到达终点,起点能到达其的点,标记一下,对角线如果仅存在1则为必经之路 E \(d_i\le n ...

  3. (持续更新)vs2012,2013,2015,2017,2019 常用的插件 与 开发中常用的工具

    这篇博客 持续更新. 小伙伴们可以复制名称,在vs的扩展和更新中去搜索下载 .其他的工具在官网下载

  4. Java IO管道流

    import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputStream; publi ...

  5. SignalR要求_转自:https://www.cnblogs.com/humble/p/3855137.html

    SignalR 服务端组件可以被部署在诸多的服务器配置中,本节描述了它所支持的操作系统版本,.NET framework,IIS.以及其他组件 二.支持的服务器操作系统 SignalR服务端组件可以被 ...

  6. 2019软工实践_Alpha(2/6)

    队名:955 组长博客:https://www.cnblogs.com/cclong/p/11862633.html 作业博客:https://edu.cnblogs.com/campus/fzu/S ...

  7. response.getWriter().println和@ResponseBody的比较及同时使用(用于回调函数)

    @RequestMapping(value = "/test", method = { RequestMethod.GET, RequestMethod.POST }) @Resp ...

  8. 交互式报告系统 Dr. Tom | 华大基因培训资料

    华大科技服务开发一套优秀的交互式结题报告系统,适用于没有代码基础的老师分析自己的数据. http://report.bgi.com/ps/login/login.html 体验之后再做评价! 见云盘: ...

  9. ln bug

    /home/hdp/testcpy sudo ln -s . /usr/lib/cpy390sourcecode cpy390sourcecode -> . sudo ln -s pwd /us ...

  10. LF: 换行,U+000A VT: 垂直定位,U+000B FF: 换页符,U+000C CR: 回车符,U+000D CR+LF:CR(U+000D)后跟LF(U+000A) NEL: 下一行,U+0085 LS: 分行,U+2028 PS: 分段,U+2029

    https://zh.wikipedia.org/wiki/換行 换行(英语:newline.line ending.end-of-line (EOL).line Feed (LF).line bre ...