0
Can we find largest number from an array of integers without using if else statements?
6 Respuestas
+ 9
What John said. You can also just say
a = [1,7,4,2,0,8,6,3,5,9]
print(max(a))
+ 5
Ternary Operator can be used too
+ 4
I didn't use any, but there still was some buried within the library.
a = [1,7,4,2,0,8,6,3,5,9]
m = a[0]
for i in a:
m = max(i, m)
print(m)
+ 4
Yes, here is an example in JavaScript: https://code.sololearn.com/WKU1By30eJZF/
+ 2
C#:
int[] a = new int[] {0, 1, 3, 6, 12};
Console.WriteLine(a.Max());
0
Well I know in java:
int max = array.get(0);
for(int i=1;i < array.length;i++){
if(array.get(i) > max) max = array.get(i);
}