gpt4 book ai didi

java - 如何在 Java 中返回带有 switch case 的随机变量?

转载 作者:行者123 更新时间:2023-12-01 11:58:38 26 4
gpt4 key购买 nike

    switch(rand){
case 1:
System.out.println(ao);
break;
case 2:
System.out.println(pf);// print your array
break;
case 3:
System.out.println(iff);
break;

case 4:
System.out.println(ie);
break;

case 5:
System.out.println(pt);
break;
case 6:
System.out.println(pn);
break;
case 7:
System.out.println(ptt);
break;
case 8:
System.out.println(mt);
break;

case 9:
System.out.println(tt);

break;
case 10:
System.out.println(it);
break;
case 11:
System.out.println(pv);
break;
case 12:
System.out.println(is);
break;
case 13:
System.out.println(to);
break;
case 14:
System.out.println(pvii);
break;
case 15:
System.out.println(pe);
break;
case 16:
System.out.println(mo);
break;
case 17:
System.out.println(ivii);
break;

case 18:
System.out.println(in);
break;
case 19:
System.out.println(rin);
break;
case 20:
System.out.println(rivii);
break;
case 21:
System.out.println(rao);
break;
case 22:
System.out.println(rpf);
break;
case 23:
System.out.println(rif);
break;

case 24:
System.out.println(rie);
break;

case 25:
System.out.println(rpt);
break;
case 26:
System.out.println(rpn);
break;
case 27:
System.out.println(rptt);
break;
case 28:
System.out.println(rmt);
break;

case 29:
System.out.println(rtt);
break;
case 30:

System.out.println(rit);
break;
case 31:
System.out.println(rpv);
break;
case 32:
System.out.println(riss);
break;
case 33:
System.out.println(rto);
break;
case 34:
System.out.println(rpvii);
break;
case 35:
System.out.println(rpe);
break;
case 36:
System.out.println(rmo);
break;


}
return null;


}

案例中的每个变量都有自己的值。我现在需要程序在每次运行时从案例中返回任何随机变量,因为这些值必须存储在数据库中。我该怎么做?

最佳答案

将变量添加到 ArrayListArray

之后你可以从列表中获取一个随机元素:

Random random = new Random();
int index = random.nextInt(arrayList.size());

System.out.println(arrayList.get(index));

关于java - 如何在 Java 中返回带有 switch case 的随机变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28154475/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com