java学习

java学习

 

随机产生4位和6位数字字符串

package com.test;


/**
 * 动态生成随机字符数组
 *  
 *
 */
public class ShortMessageCodeUntil
{


    /**
     * 随机生成4位数字字符数组
     *  
     * @return rands
     */
    public static char[] generateCheckCode()
    {
        String chars = "0123456789";
        char[] rands = new char[4];
        for (int i = 0; i < 4; i++)
        {
            int rand = (int) (Math.random() * 10);
            rands[i] = chars.charAt(rand);
        }
        return rands;
    }


    /**
     * 随机生成6位数字字符数组
     *  
     * @return rands
     */
    public static char[] generateCheckPass()
    {
        String chars = "0123456789";
        char[] rands = new char[6];
        for (int i = 0; i < 6; i++)
        {
            int rand = (int) (Math.random() * 10);
            rands[i] = chars.charAt(rand);
        }
        return rands;
    }
public static void main(String[] args) {
    ShortMessageCodeUntil sm = new ShortMessageCodeUntil();
    System.out.println(sm.generateCheckCode());
    System.out.println(sm.generateCheckPass());
}

}

posted on 2013-03-22 11:06 杨军威 阅读(826) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜