【发布时间】:2021-01-26 22:51:48
【问题描述】:
2 周后。我需要用一个负整数打破 while 循环,但我一直无法成功实现它。这是我在左右编辑无济于事之前的原始代码。 Print 中的值在循环之外。
public class AssignmentQuestion2 {
public static void main(String[] args) {
//write your code here
ArrayList<Integer> rainfall = new ArrayList<Integer>();
Scanner in = new Scanner(System.in);
System.out.println("Please input rainfall(Input negative value to exit)");
while (in.hasNextInt()) {
if (in.hasNextInt()) {
rainfall.add(in.nextInt()); //how to input into array
System.out.println(calculateAverage(rainfall)); //average
System.out.println(findSmallest(rainfall)); //smallest input
System.out.println(findLargest(rainfall)); //largest input
} else {
in.close();
}
}
}
【问题讨论】:
标签: java while-loop break