Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Forming minimum value and forming maximum value
Forming minimum value and forming maximum value
Public static void main(String[] args)

{

int Arr[] =

{ 1, 3, 4, 56, 77, 88, 33, 23, 2 1 };

int max = 0;

int min = 0;

int sum = 0;

for(int I = 0; I < array length; i++)

{

sum+= Arr[I];

for(int j = 0; J< array length; j++)

{

if(Arr[I]& gt; arr[j]amp; & ampmax & ltArr[j]) // Here you need to judge whether to change the current maximum if it is greater than the current maximum.

{

max = Arr[I];

}

If (min == 0)// Since the previous minimum value was 0, it needs to be changed first.

{

min = Arr[I];

if(Arr[I]& lt; arr[j]amp; & ampmin & gtArr[j])

{

min = Arr[I];

}

} Otherwise,

{

if(Arr[I]& lt; arr[j]amp; & ampmin & gtArr[j])

{

min = Arr[I];

}

}

}

}

System.out.println ("The maximum value in the array is:"+max ");

System.out.println ("The minimum value in the array is"+min ");

System.out.println ("The sum of the elements in the array is"+sum ");

}

I changed your code. .. and upstairs said that your judgment was incomplete.

So there is a little problem when executing. Your outermost loop needs to start from 0. The first of the array is zero-based.

Otherwise, there will be one less number to cycle.