不用那么麻烦吧?
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
for (int i = 0; i < a; i++) {
list.add(scanner.nextInt());
}
int b = scanner.nextInt();
for (int i = 0; i < b; i++) {
int c = scanner.nextInt();
ArrayList<Integer> temp = new ArrayList<Integer>();
for (int j = 0; j < list.size(); j++) {
if(c < list.get(j)) {
temp.add(j);
}
}
if(temp.size() == list.size()) {
System.out.println(1);
}
else if (temp.size() == 0) {
System.out.println(0);
}
else {
int count = 1;
for (int j = 1; j < temp.size(); j++) {
if(temp.get(j) - temp.get(j-1) > 1) {
count++;
}
}
System.out.println(count);
}
}
}