0
java
Have there any function in Java which can show us maximum and minimum of integer variables which we Scannered ? (Variables more than two ,so I can not use Math.max or Math.min)
2 Answers
+ 2
If the values are in an array or list, then you can use Collections.max() and Collections.min()
Also there are max() and min() methods on IntStream
https://www.google.com/amp/s/www.geeksforgeeks.org/collections-max-method-in-java-with-examples/amp/
https://www.google.com/amp/s/www.geeksforgeeks.org/intstream-max-in-java-with-examples/amp/
+ 1
you can have Math.max inside a Math.max. e.g
int a = 30;
int b = 40;
int c = 50;
int d = 60;
System.out.println(Math.max(Math.max(a, b), c));
System.out.println(Math.max(Math.max(a, b), Math.max(c, d)));