每次循环后都会count更新count1。输入后Scanner,我没有得到任何输出。
Scanner sc = new Scanner(System.in);
int t = sc.nextInt(); // t=1
while (t != 0) {
int n = sc.nextInt(); // n=5
int a[] = new int[n]; // a = { 1,2,5,6,7 }
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int count = 0, count1 = 0;
for (int i = 0; i < n; i++) {
if ((a[i + 1] - a[i]) > 2) {
count++;
} else {
count1++;
}
}
// this doesn't get printed
System.out.println(count + 1 + " " + count1);
t--;
}