import java.Math;
public class gffgf {
public static void main(String[] args) {
// T000 Auto-generated method Stub
//建立字串陣列放置所有可能亂數抽出的結果圖片名稱
String[] pic = new String[] {"apple", "cherry", "grape", "guava","lemon", "melon"
//初始化x存放陣列內index=0的內容,y存放陣列內index=1的內容,z存放陣列內index=2內容
string x=pic[0], y=pic[1], z=pic[2];
//使用Math.random()產生1陣列元素個數之間的亂數數值.pic.length為陣列元素個數
int index1 = (int)(Math.random()*pic.length) +1;
int index2 = (int)(Math.random()*pic.length) +1;
int index3 = (int)(Math.random()*pic.length) +1;
//將index1~3轉成陣列的索引值(index)
index1 = index1 - 1;
index2 -= 1; //index2 = index2 - 1
index2 -= 1; //index3 = index3 - 1
System.out.println(index1 + " " + index2 + " " + index3);
//取出並顯示抽出3張圖片後的結果
x = pic[index1];
y = pic[index2];
z = pic[index3];
System.out.println(x + " " + y + " " + z);
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: