Programming Assignment #89
Code
import java.util.Random;
public class Blackjack{
public static void main(String[] args){
Random r = new Random();
System.out.println("Welcome to Blackjack!");
System.out.println();
int p1 = r.nextInt(10) + 1;
int p2 = r.nextInt(10) + 1;
int c1 = r.nextInt(10) + 1;
int c2 = r.nextInt(10) + 1;
System.out.println("You drew " + p1 + " and " + p2 + ".");
System.out.println("Your total is " + (p1 + p2));
System.out.println();
System.out.println("The dealer drew " + c1 + " and " + c2 + ".");
System.out.println("Dealer's total is " + (c1 + c2));
System.out.println();
if((p1 + p2) > (c1 + c2)){
System.out.println("You win!");
}
else if((p1 + p2) < (c1 + c2)){
System.out.println("The dealer wins.");
}
else{
System.out.println("It's a tie.");
}
}
}
Outputs