import java.util.Scanner;
public class StrictDescending
{
public static void main(String[] args)
{
final int SENTINEL = 1000;
Scanner n = new Scanner(System.in);
int prev = n.nextInt();
if (prev >= SENTINEL)
{
System.out.println("Empty list");
return;
}
while (true)
{
int next = n.nextInt();
if (next >= SENTINEL) {
break;
} else if (next >= prev) {
System.out.println("No, the list is not in descending order.");
}
prev = next;
}
System.out.println("Yes, the list in in descending order.");
}
}
我想运行这个程序,并通过一个3位数的整数列表,当下面的3位整数不降序我想打印没有列表不下降,也如果该列表是在它下降涉及到非3位numbr像1000我想打印是列表中降序我输出的作品,但是当我把整数非降列表它吐出来的两个输出语句有一个java代码输出错误
对于此输入
150 140 140 120 1000
我得到
No, the list is not in descending order.
No, the list is not in descending order.
Yes, the list in in descending order.
时,我只是想
No, the list is not in descending order.
我该如何解决这个问题? – user6451702
看看我提供的链接并接受重复的 –
听起来是正确的。这行将在每次调用时执行:System.out.println(“是,列表按降序排列。”); – obi1