1 public class Wjf
2 {
3 public static void main(String[] args)
4 {
5 double randnum = Math.random();
6 System.out.println("你成功的幾率為:" + randnum);
7 System.out.println("請問是否繼續?[y/n]:");
8 try
9 {
10 char i =(char)System.in.read();
11 while (i != 'y' && i != 'n' && i != 'Y' && i !='N')
12 {
13 System.out.println("輸入有誤");
14 System.out.println("請問是否繼續?[y/n]:");
15 try
16 {
17 i = (char)System.in.read();
18 }
19 catch(Exception e)
20 {}
21 }
22
23 if (i == 'y' || i == 'Y')
24 {
25 System.out.print("您:");
26 if (Math.random() <= randnum)
27 {
28 System.out.println("success!!");
29 }
30 else
31 {
32 System.out.println("fail!!");
33 }
34 }
35 else
36 {
37 System.out.println("退出吧你");
38 }
39 }
40 catch(Exception e)
41 {};
看thinking in java時想到的一個代碼..實現了以前看到的一個小小程 序的一個功能..嘿嘿..不過這里面的蠻多要改的.....下次說
芳兒寶貝.我愛你