How to find the most significant number of negative integers in java? I have the following code and work well with positive integers. This is the code:
int max = 0; // not initialsing it also makes it 0
int[] n = {-1,-2,-3,-4};
for(int i = 0; i < n.lenght; i++)
if(max < n[i])
max = n[i];
Now, I can solve it by reducing the max
variable to -5
or something below -4
, but this is inefficient because we don't know the lowest value.
So, how can it be achieved?