首页 > 其他 > 详细

身份证和查字母的数量

时间:2017-04-26 15:20:57      阅读:303      评论:0      收藏:0      [点我收藏+]
import javax.management.RuntimeErrorException;


public class Test11 {
public static void main(String[] args) {
//1.有一身份证号,判断此为男还是女,基于此方法,写一个算法,判断一个身份证号为男还是女。
////2.求出字符串中有多少种字符,以及每个字符的个数
//    static void printCharInfo(String str)
//     例如有字符串 str="apple is a apple.";
    System.out.println(isMan("203000199511502212"));
    printchar("apple is an apple.");
    
}

public static void printchar(String str){
    while(str.length()!=0){
        String b=str.substring(0, 1);
        int oldlength=str.length();
        str=str.replace(b,"");
        System.out.println(b+":"+(oldlength-str.length()));
        
    }

}

public static boolean isMan(String id){
    if(id.length()!=15 && id.length()!=18)    {
         throw new RuntimeException("输入信息有误");
    }
    int value=0;
    if(id.length()==15){
        value=Integer.valueOf(id.substring(14));
    }else{
        value=Integer.valueOf(id.substring(16, 17));}
    if (value%2==0){
        return false;
    
    }else{
        return true;
    }


}

}

 

身份证和查字母的数量

原文:http://www.cnblogs.com/zyy1130/p/6768484.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!