解题思路:对输入的数组排序以后 分三种情况
注意事项:
参考代码:
public class 小O的乘积 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int len = in.nextInt();
int[] arrays = new int[len];
for (int i = 0; i < arrays.length; i++) {
arrays[i] = in.nextInt();
}
int cj = 0;
Arrays.sort(arrays);
if(arrays[0]>0 && arrays[arrays.length-1]>0) {
cj = arrays[0] * arrays[1];
}
else if(arrays[0]<0 && arrays[arrays.length-1]<0) {
cj = arrays[arrays.length-1] * arrays[arrays.length-2];
}
else {
cj = arrays[0] * arrays[arrays.length-1];
}
System.out.println(cj);
}
}
}
0.0分
0 人评分