-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestElement.java
More file actions
45 lines (31 loc) · 1.03 KB
/
LargestElement.java
File metadata and controls
45 lines (31 loc) · 1.03 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package DSA;
import java.util.Arrays;
import java.util.Scanner;
public class LargestElement {
public static void main(String[] args){
//THIS PROGRAM RETURNS THE LARGEST ELEMENT IN THE ARRAY.
Scanner sc = new Scanner(System.in);
int size=0;
System.out.print("Enter the size of array : ");
size = sc.nextInt();
sc.nextLine();
int[] arr = new int[size];
System.out.println("\nEnter the array elements : ");
for(int i=0;i<arr.length;i++){
System.out.printf("Element %d : ",i);
arr[i]=sc.nextInt();
sc.nextLine();
}
int largest = arr[0];
for(int i=1;i<arr.length;i++){
if(largest<arr[i]){
largest=arr[i];
}
}
System.out.print("\nArray is : ");
for(int i=0;i<arr.length;i++){
System.out.print(arr[i] + " ");
}
System.out.printf("\nLargest element : %d",largest);
}
}