|
import java.io.*;
public class Craps { public static void main( String args[] ) throws IOException { DataInputStream input = new DataInputStream(System.in); int d1,d2; int bet,point,total;
total = 500; System.out.println( "Enter your bet" );
bet = Integer.parseInt(input.readLine());
d1 = (int) (Math.random()*6 + 1); d2 = (int) (Math.random()*6 + 1); System.out.println(" Your first roll was" + d1+d2);
if (d1+d2==7) { System.out.println("You win"); total = total + bet; } if (d1+d2!=7) { point = d1+d2; d1 = (int) (Math.random()*6 + 1); d2 = (int) (Math.random()*6 + 1); System.out.println(" Your roll was" + d1+d2); while (d1+d2 !=7 && d1+d2!=point) { d1 = (int) (Math.random()*6 + 1); d2 = (int) (Math.random()*6 + 1); System.out.println(" Your roll was " + d1+" and "+d2); } if (d1+d2==7) { System.out.println("You lose"); total = total - bet; } if (d1+d2==point) { System.out.println("You win"); total = total + bet; } } System.out.println("You have " + total + " dollars left"); } // end of main } // end of class Craps
|