java _根據身份證號碼辨別性別的代碼


 


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哈!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM