java入門問題

2012-10-22 8:45 am
有咩網教人寫java ga......
另外, 如果我想random 咁出一樣野,咁應該點寫?
例如 玩抽獎,
有九個格.
口口口
口口口
口口口

我想將1-9 隨機放入9個格仔,應該點寫呢?
更新1:

THX 其實想睇下個邏輯. 如果我係有圖片, 1.jpg 2.jpg ... 9.jpg 咁應該點做? 假設有3x3 既backgound. 同埋我想問埋,假設只有1份1號獎, 1份2號獎, 3份3號,4個4獎.... 咁應該點樣random 放佢地呢? thx a lot

更新2:

ya, if they choose 1 , they can get first prize.

更新3:

OK, THZ GOOD WEBSITE. do you receive my email?

回答 (2)

2012-10-23 12:07 am
✔ 最佳答案
do you want to see the 9 squares? or just the progamming logic you want...?

2012-10-22 16:07:12 補充:
public class play {
public static void main(String[] arg){
int[][] x = new int[3][3];
for (int i=0;i<x.length;i++){
for (int j=0;j<x.length;j++){
int num = (int) (1+Math.random()*9);
x[i][j] = num;//insert the numbers
}
}
for (int g=0;g<x.length;g++){
for (int i=0;i<x.length;i++){
System.out.print(" "+x[g][i]); //print number
}
System.out.println();
}
}
}

2012-10-24 10:13:36 補充:
BufferedImage img = null;
try {
img = ImageIO.read(new File("strawberry.jpg"));
} catch (IOException e) {
}
//for image

2012-10-24 10:15:06 補充:
ask the user for a number, if they get that number then they get that prize for that number??

2012-10-24 11:49:14 補充:
i can't post much code here.... hehe....
you know java? have a look at JOptionPanel

2012-10-26 05:05:59 補充:
nope....

good website? android phone java tutorial... that's how i learn my C/C++ &python
2012-10-30 1:59 am
之前讀完個Java SE 6課程
我覺得導師教得幾好
有免費試睇
由淺入深
詳細可以參考OCP: Java SE 6 Programmer (SCJP) 認證課程
http://www.systematic.com.hk/scp.htm


收錄日期: 2021-04-20 13:19:57
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20121022000051KK00025

檢視 Wayback Machine 備份