[问题] 如何将乱数产生器的数字带入文字阵列?

楼主: jayzhuang (Jay)   2017-03-19 18:03:53
最近练习遇到出题人给的练习....
请求诸位大大帮忙,怎么把乱数产生出来的数字,
放到列举好的文字阵列里面?
就像这样,假如我要做的是抽签,随机抽取0~3共4个数字,
假如四个数字都是不同的文字,就算过关。
但是从来没有用过将乱数产生的数字直接带入矩阵....
想问大大该怎么做最关键的那步,将数字带入矩阵,我已经设定好了,
但差这一步:
public class HW2_16 {
public static void main(String[] args) {
String[] word = new String[4];
word[0]="神";
word[1]="奇";
word[2]="宝";
word[3]="贝";
//这边是设定矩阵范围0~3共四个数字
java.util.Scanner sc = new java.util.Scanner(System.in);
// 然后设定每要抽一次,直接产生一个乱数,
System.out.print("A第一次抽签:");
System.out.println((int)(Math.random()*4));
System.out.print("B第一次抽签:");
System.out.println((int)(Math.random()*4));
System.out.print("A第二次抽签:");
System.out.println((int)(Math.random()*4));
System.out.print("B第二次抽签:");
System.out.println((int)(Math.random()*4));
System.out.print("A第三次抽签:");
System.out.println((int)(Math.random()*4));
System.out.print("B第三次抽签:");
System.out.println((int)(Math.random()*4));
System.out.print("A第四次抽签:");
System.out.println((int)(Math.random()*4));
System.out.print("B第四次抽签:");
System.out.println((int)(Math.random()*4));
//但是A与B两位抽取的乱数结果,怎么以文字显示出阵列的各个字?
System.out.println("A抽取的文字结果为:");
System.out.println("B抽取的文字结果为:");
}
}
作者: cowbaying (是在靠北喔)   2017-03-19 18:06:00
作业自己写好吗? 你都会指定值进去了 读出来却不会?

Links booklink

Contact Us: admin [ a t ] ucptt.com