(工具)返回随机文字数字

package utilfengzhuang;

import java.util.Random;

public class fanhuisuijiwenzi {
    protected static char randomsys[]=
        new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    protected static Random random=new Random();
    public static void main(String[] args) {
    int length=15;
    fanhuisuijiwenzi fan=new fanhuisuijiwenzi();
    String aa=fan.checkwenzi(length);
    System.out.println("随机文字:"+aa);
    String bb=fan.checkshuzi(length);
    System.out.println("随机数字:"+bb);
}
//返回随机文字
    public static String checkwenzi(int length){
        StringBuffer bu=new StringBuffer();
        for(int i=0;i<length;i++){
            bu.append(randomsys[random.nextInt(randomsys.length)]);
        }
        return bu.toString();
        
    }
    //返回随机数字
    public static String checkshuzi(int length){
        StringBuffer bu=new StringBuffer();
        for(int i=0;i<length;i++){
            bu.append(randomsys[random.nextInt(length)]);
        }
        return bu.toString();
    }
}

 2.隐藏手机号中间四位:

public class yincang {
public static void main(String[] args) {
    String num="15211115555";
    String aa=num.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    System.out.println(aa.toString());
}
}

3.大额度金额,用逗号相隔:

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class tihuan{
public static void main(String[] args) {
    String prize="10000000.462";
    NumberFormat num=null;
    double a=Double.parseDouble(prize);
    System.out.println(a);
    num=new java.text.DecimalFormat("###,###");
    System.out.println(num.format(a));
    
    /*Integer mantissaLength=0;

        try{
            NumberFormat formater=null;
            double num=Double.parseDouble(prize);
                if(mantissaLength==0){
                         formater=new java.text.DecimalFormat("###,###");
                    }else{
                        StringBuffer buff=new StringBuffer();
                        buff.append("###,###.");
                        for(int i=0;i<mantissaLength;i++){
                            buff.append("#");
                        }
                        formater=new java.text.DecimalFormat(buff.toString());
                    }
                String out=formater.format(num);
                System.out.println(out);
        }catch(Exception e){
            e.printStackTrace();
}*/
}

}

 

posted @ 2017-03-09 15:56  烟雨观春柳  阅读(193)  评论(0)    收藏  举报