还是水题, 不过, 之前的我应该是不会写的, 因为要是实现一行输入(使用BufferedReader和InputStreamReader的组合方式), 代码如下:
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { private static int oddNum = 0; // 记录奇数的数量 private static int evenNum = 0; // 记录偶数的数量 public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] str = new String[n]; str = br.readLine().split(" "); for (int i=0; i<n; i++) { OddOrEven(Integer.parseInt(str[i])); } System.out.print(oddNum + " " + evenNum); } public static void OddOrEven(int num) { if(num % 2 ==0) { // 意味着这个数是偶数 evenNum++; } else { oddNum++; } } }