public static void main(String[] args)
{
int Arr[] =
{ 1, 3, 4 , 56, 77, 88, 33, 23, 21 };
int max = 0;
int min = 0;
int sum = 0;
for (int i = 0; i < Arr.length; i++)
{
sum += Arr[i];
< p> for (int j = 0; j < Arr.length; j++){
if (Arr[i] > Arr[j] && max < Arr[j] ) //Here you need to judge if it is larger than the current maximum value, then change the current maximum value
{
max = Arr[i];
}< /p>
if (min == 0)//Since the previous minimum value was 0, it needs to be changed first
{
min = Arr[i];
p>if (Arr[i] < Arr[j] && min > Arr[j])
{
min = Arr[i];
}
} else
{
if (Arr[i] < Arr[j] && min > Arr[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 made some changes to your code. ..The person above also said that your judgment is not complete
So there is a slight problem during execution. Also, your outermost loop needs to start from 0.
The first one in the array starts from 0
Otherwise, one less number will be looped