Java的简单随机数产生

mac2026-09-23  11

##创建三个数组,然后分别随机从里面输出三个字符串 主要代码程序如下:

public class km { public static void main(String[] args) { // 你可以随意的加上其他术语 String[] wordone={"43","foot","love","you","forever","strong"}; String[] wordtwo={"3434","like","best","branded","values"}; String[] wordthere={"catch","based","-6666","mind","share"}; //计算每一组有多少个名词术语 int onelength=wordone.length; int twolength=wordtwo.length; int therelength=wordthere.length; //产生随机数字 int rand1=(int) (Math.random() * onelength); int rand2=(int) (Math.random() * twolength); int rand3=(int) (Math.random() * therelength); //组合出专家术语 String phrase=wordone[rand1]+" "+wordtwo[rand2]+" "+wordthere[rand3]; //输出 System.out.println("it is "+phrase); } }

(注意:当你自己输入这个程序时,不要在字符串中间换行(也就是“ ”符合之间),不然的话程序无法通过编译程序)

最新回复(0)