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:
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的更多相关文章
- 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 ...
- LeetCode Kth Largest Element in an Array
原题链接在这里:https://leetcode.com/problems/kth-largest-element-in-an-array/ 题目: Find the kth largest elem ...
- Kth Largest Element in an Array 解答
Question Find the kth largest element in an unsorted array. Note that it is the kth largest element ...
- Lintcode: Kth Largest Element 解题报告
Kth Largest Element Find K-th largest element in an array. Note You can swap elements in the array E ...
- 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 / ...
- 【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 ...
- 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 ...
- 堆排序 && Kth Largest Element in an Array
堆排序 堆节点的访问 通常堆是通过一维数组来实现的.在数组起始位置为0的情形中: 父节点i的左子节点在位置(2*i+1); 父节点i的右子节点在位置(2*i+2); 子节点i的父节点在位置floor( ...
- [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 ...
随机推荐
- 命令备忘 ss
简介: Socket Statistics(ss)命令类似于netstat,它用于显示各种有用的网络套接字信息. 长时间看,已经注意到netstat这个命令程序已经过时了.从而代替netstat的是s ...
- C语言scanf函数返回值小记
scanf scanf是C标准库stdio里面定义的用于获取用户输入的函数,具体的介绍可以在CppReference上看到.scanf的返回值是已经成功赋值的变量个数,也就是说在 scanf(&quo ...
- hive(2)数据类型和文件格式
基本的数据类型 Hive支持关系型数据中大多数基本的数据类型,同时也支持关系型数据库中很少出现的三种集合数据类型. 集合数据类型 Hive中的列支持使用struct.map.array集合数据类型,下 ...
- MySQL事务(脏读、不可重复读、幻读)
1. 什么是事务? 是数据库操作的最小工作单元,是作为单个逻辑工作单元执行的一系列操作:这些操作作为一个整体一起向系统提交,要么都执行.要么都不执行:事务是一组不可再分割的操作集合(工作逻辑单元): ...
- go的flag模块使用例子
package main import ( "flag" "fmt" "strconv" ) func main() { port := f ...
- (二)SQL学习之数据定义类SQL
以mysql为例 对数据库的常用操作 创建数据库:CREATE DATABASE mydb; 删除数据库:DROP DATABASE mydb; 切换数据库:USE mydb; 查询数据库:SHOW ...
- Linux内存中的Cache真的能被回收吗? 【转】
在Linux系统中,我们经常用free命令来查看系统内存的使用状态.在一个RHEL6的系统上,free命令的显示内容大概是这样一个状态: [root@tencent64 ~]# free ...
- SpringBoot整合Hibernate
编写配置文件 <!--配置读取properties文件--> <context:property-placeholder location="classpath:jdbc. ...
- GIS地理工具案例教程——批量去除多边形的之间的间隙
GIS地理工具案例教程--批量去除多边形的之间的间隙 商务合作,科技咨询,版权转让:向日葵,135-4855__4328,xiexiaokui#qq.com 问题:几乎所有的手工生产的数据,都存在多边 ...
- Vehicle routing with Optaplanner graph-theory
Vehicle routing with Optaplanner - Stack Overflow https://stackoverflow.com/questions/22285252/vehic ...