【问题描述】:
import java.io.*;
import java.util.Arrays;
class Test
{
static private void getElements(int[] arr, int n)
{
if (n == 0 || n==1)
{
System.out.print(-1);
System.out.print(" ");
System.out.print(-1);
System.out.print("n");
}
int small = Integer.MAX_VALUE;
int second_small = Integer.MAX_VALUE;
int large = Integer.MIN_VALUE;
int second_large = Integer.MIN_VALUE;
int i;
for (i = 0;i
for (i = 0;i < n;i++)
{
if (arr[i] second_large && arr[i] != large)
{
second_large = arr[i];
}
}
System.out.println("Second smallest is "+second_small);
System.out.println("Second largest is "+second_large);
}
public static void main(String[] args)
{
int[] arr = {1, 2, 4, 6, 7, 5};
int n = arr.length;
getElements(arr, n);
}
}
我看不懂代码。谁能解释一下将 Integer.Max_Value 分配给小值,将 integer.min_value 分配给大数的逻辑,并解释一下 integer.max_value 和 min_value 的使用以及何时使用它们。
【讨论】:
© 版权声明
本站下载的源码均来自公开网络收集转发二次开发而来,
若侵犯了您的合法权益,请来信通知我们1413333033@qq.com,
我们会及时删除,给您带来的不便,我们深表歉意。
下载用户仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,访问及下载者下载默认同意本站声明的免责申明,请合理使用切勿商用。
THE END
暂无评论内容