class fuxi_6 { static int x = 0; static int y = 0; public static void main(String[] args) { String[] id = new String[20]; id[0] = "62282609890501453X"; id[1] = "524895756658292982"; id[2] = "652555199111226362"; id[3] = "821525200601245613"; id[4] = "246255625336266653"; id[5] = "21525219940924358X"; for (int i = 0; i < 6; i++) { String sex = id[i].substring(16, 17); //取指定位置的值(16位之后,17位结束;) int b = Integer.parseInt(sex);//强制类型转换 if (b % 2 == 0) { x += 1; } else { y += 1; } } System.out.print("男生:" + x + "人"); System.out.print("女生:" + y + "人"); } }
我还在学习使用这个博客 ,才发现可以插入代码..O(∩_∩)O哈!