和为2、3、12,输;
和为7、11,赢;
其他数字则再投,直到和为7则输,与前一次相同则赢
代码:
package com.im;
public class Demo630 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int disc = getDisc();
if(disc==2 || disc==3 || disc==12){
System.out.println("You win");
System.exit(1);
}else if(disc==7 || disc==11){
System.out.println("You lose");
System.exit(2);
}
int point = disc;
// System.out.println(“point is ” + point);
//
do{
point = disc;
System.out.println(“point is ” + point);
disc = getDisc();
}while(disc != 7 && disc !=point);
if(disc == 7){
System.out.println("You lose");
}else{
System.out.println("You win");
}
}
public static int getDisc(){
int x = 1 + (int)(Math.random()*6);
int y = 1 + (int)(Math.random()*6);
System.out.println("You rolled " + x + " + " + y + " = " + (x+y));
return x+y;
}
}