手机尾号判断是否吉利 Java

手机尾号判断是否吉利 Java,第1张

package Demo01;
import java.util.Scanner;
public class SelDemo {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的号码:");
        String strSel = sc.next();
        GetLast4 r4 = new GetLast4();
        if(!r4.notRightSel(strSel)){
            System.out.println("输入的位数有误!");
        }else{
            if(r4.notInlandSel(strSel)){
                System.out.println("非大陆手机号!");
            }else{
                if(r4.isDianxin(strSel)){
                    System.out.println("电信号码!");
                }
                int lastfour = r4.Last4(strSel);
                int cal = r4.calculater(lastfour);
                String resule = r4.cTiao(cal);
                System.out.println(resule);
            }
        }
    }
}
package Demo01;

public class GetLast4 {
    public int Last4(String strSel){
        strSel=strSel.substring(7,11);//截取后4位
        int intSel = Integer.parseInt(strSel);//转为interesting
        return intSel;
    }
    public int calculater(int lastfour){
        lastfour = lastfour%80;//对结果进行计算
        return lastfour;
    }
    public String cTiao(int lastfour){
        String arr[] = {"吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",
                "吉","不吉利","非常吉利","好不吉利","岌岌可危","安全","不安全","大吉大利",};
        return arr[lastfour];//通过数组元素下标返回结果
    }
    public Boolean notRightSel(String strSel){
        if(strSel.length()!=11){//判断手机号码位数是否正确
            return false;
        }else{
            return true;
        }
    }
    public Boolean notInlandSel(String strSel){
        if(strSel.indexOf('1')!=0){//判断是否为大陆手机号码
            return true;
        }else{
            return false;
        }
    }
    public Boolean isDianxin(String strSel){
        String seltop = strSel.substring(0,3);
        if(seltop.equals("137")){//判断是否为137开头
            return true;
        }else{
            return false;
        }
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/870459.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存