首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

随机步骤的应用

2013-08-13 
随机方法的应用/** * 随机取出6位的字符串(全是小写字母) */public class RandomStr {public static void

随机方法的应用

/** * 随机取出6位的字符串(全是小写字母) */public class RandomStr {public static void main(String[] args) {String result = "";for (int i = 0; i < 3; i++) {//Math.random()的范围是大于0小于1//如果是不区分大小写,应该如下所示;//如果只有大写,就应该是只有Math.random()*26+65且只循环6次;//如果只有小写,就应该是只有Math.random()*26+97且也只循环6次int intval = (int) (Math.random() * 26 + 97);int intval2 = (int) (Math.random() * 26 + 65);result = result + (char) intval + (char) intval2;}System.out.println(result);}}

?

热点排行