java随机生成汉字

 

 

public static void main(String[] args) {
          String str = null;
          int hs, ls; 
          Random random = new Random();
          hs = (176 + Math.abs(random.nextInt(39))); 
          ls = (161 + Math.abs(random.nextInt(93)));
          byte[] b = new byte[2];
          b[0] = (new Integer(hs).byteValue());
          b[1] = (new Integer(ls).byteValue());
          try {
            str = new String(b, "GBk"); //转成中文
            System.out.println(str);;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

 

posted @ 2017-10-12 17:00  这个名字想了很久~  阅读(939)  评论(0编辑  收藏  举报