0
how does the array is finding the smallest and largest number itself?
public static void main(String args[]) {int nums[] = new int[10];int min, max;nums[0] = 99;nums[1] = -10;nums[2] = 100123;nums[3] = 18;nums[4] = -978;nums[5] = 5623;nums[6] = 463;nums[7] = -9;nums[8] = 287;nums[9] = 49;Chapter 5: More Data Types and Operators 139min = max = nums[0];for(int i=1; i < 10; i++) {if(nums[i] < min) min = nums[i];if(nums[i] > max) max = nums[i];}System.out.println("min and max: " + min + " " + max);}} why its not printing the first smallest no it gets in first if statement? like-10.. explain plz
5 ответов
+ 2
it's not printing the first smallest number because that number is replaced with a smaller number before you ask for it to be printed to the screen.
0
yeah you are right Bod
0
u need to put the println inside the for loop
0
you can use Arrays.sort(*your Array*); to sort your Array
0
why not iterate using I< num.length?
or than I<10