+ 1

How to find the max value of an array? Help pls...

elements of array should be entered at runtime

2nd Aug 2018, 12:57 PM
Sumit Singh
Sumit Singh - avatar
4 Answers
+ 6
import java.util.Scanner; import java.util.Collections; import java.util.Arrays; public class Program{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How Many Numbers?"); int l = sc.nextInt(); Integer arr[] = new Integer[l]; for(int i=0; i<l; i++) arr[i] = sc.nextInt(); int min = Collections.min(Arrays.asList(arr)); int max = Collections.max(Arrays.asList(arr)); System.out.println("Max: " + max +"\nMin: " + min); } }
2nd Aug 2018, 1:14 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 1
bro values should be entered by user at runtime.
2nd Aug 2018, 1:01 PM
Sumit Singh
Sumit Singh - avatar
+ 1
thank u bro
2nd Aug 2018, 1:50 PM
Sumit Singh
Sumit Singh - avatar