名字生成器 - 再也不用担心给孩子起名了
生活随笔
收集整理的這篇文章主要介紹了
名字生成器 - 再也不用担心给孩子起名了
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
使用gbk字庫,減少生僻字?
import java.util.Random;/*** Created on 2020-10-02*/ public class GenerateName {public static void main(String[] args) {printName("韓", 2, 800);}/*** 打印名字* @param lastName 姓* @param digits 名字長度* @param count 生成數(shù)量*/public static void printName(String lastName, int digits, int count) {StringBuilder stringBuilder = new StringBuilder();for (int i = 0; i < count; i++) {if (i % 10 == 0) {stringBuilder.append("\n");}stringBuilder.append(lastName);stringBuilder.append(getRandom(digits));stringBuilder.append(" ");}System.out.println(stringBuilder.toString());}@SuppressWarnings("checkstyle:MagicNumber")public static String getRandom(int len) {String ret = "";for (int i = 0; i < len; i++) {String str = null;int hightPos, lowPos;Random random = new Random();hightPos = (176 + Math.abs(random.nextInt(39)));lowPos = (161 + Math.abs(random.nextInt(93)));byte[] b = new byte[2];b[0] = (new Integer(hightPos).byteValue());b[1] = (new Integer(lowPos).byteValue());try {str = new String(b, "GBK");} catch (Exception e) {System.out.println(e);}ret += str;}return ret;}}?
總結(jié)
以上是生活随笔為你收集整理的名字生成器 - 再也不用担心给孩子起名了的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【设计模式 00】设计模式的六大原则
- 下一篇: git 移动分支指针_理解git 中的H