-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargest.java
More file actions
30 lines (24 loc) · 854 Bytes
/
Largest.java
File metadata and controls
30 lines (24 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.mycompany.largest;
/**
*
* @author ERIC
*/
public class Largest {
public static void main(String[] args) {
// Input array
int[] array = {34, 23, 12, 45, 67, 89, 234, 26, 10, 30, 43};
// Initialize the largest element
int largest = array[0]; // Assume the first element is the largest
// Loop through the array to find the largest element
for (int i = 1; i < array.length; i++) {
if (array[i] > largest) {
largest = array[i]; // Update largest if current element is greater
}
}
// Print the largest element
System.out.println("The largest element in the array is: " + largest);
}
}