接收 5,9,7 作为输出..预期应该只有 9..下面是代码:
public class GreatestNoInArray {
public static void main(String[] args) {
int a[]= new int[] {1,2,5,9,7};
int big=a[0];
for (int i=1; i<a.length; i++){
if (big<a[i])
big=a[i];
System.out.println(a[i]);
}
}
}
请帮忙
最佳答案
为了获得预期的答案,您需要在循环外打印big
(而不是a[i]
)
关于java - 从数组中获取最大整数时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21438807/