| 发表于:2007-09-13 14:59:498楼 得分:0 |
import java.util.*; public class test24 { public static void main(string[] args) { random r = new random(); system.out.println( "please choose your gift! "); for(gift g : gift.values()) { system.out.print(g.tostring() + " "); } system.out.print( "\n " + "input: "); scanner sc = new scanner(system.in); string s = sc.nextline(); for(gift g : gift.values()) { if(g.tostring().equalsignorecase(s)) { if (r.nextint(100) + 1 < g.getp()) { system.out.println( "you get " + g.tostring()); } else { system.out.println( "sorry "); } } } } } enum gift { a(50), b(15), c(25), d(10); private int p; private gift(int p) {this.p = p;} public int getp() {return p;} } | | |
|