Why do arrays in java choose the biggest? [closed]
- by Trycon
I'm new to java so I was reading my book with these code:
public class mainb1 {
public static void main (String[] args)
{
//datatype name = expression;
//food
int min, max;
int num[] = new int[10];
num[0]=99;
num[1]=90;
num[2]=-100;
num[3]=100;
num[4]=23;
num[5]=50;
num[6]=123;
num[7]=3123;
num[8]=2;
num[9]=923;
min=max=num[1];
for(int x=0;x<10;x++)
{
if(num[x]<min)min=num[x];
if(num[x]>max)max=num[x];
}
System.out.println("Min: "+min+" max: "+max);
}
}
It chose the biggest and the smallest. I don't get it if max was 99, then the last one that is lesser than min is 2? How did this array choose to pick the smallest and the biggest? Can someone explain?