Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.Random;
  2. public class TwentyOne {
  3. int card1;
  4.     public static void main(String a[]){  
  5.         // Generates a random number between 1 and 13
  6.         card1 = getRandomInteger(13, 1);
  7.  
  8.         System.out.println("Dealer: "
  9.           + card1);
  10.  
  11.     }
  12.    
  13.     /*
  14.      * Java method to return random integer between 0 and
  15.      * given number. Pay attention to brackets while casting
  16.      * (int) Math.random*max will return incorrect result.
  17.      */
  18.     public static int getRandom(int max){
  19.         return (int) (Math.random()*max);
  20.     }
  21.    
  22.    
  23.     /*
  24.      * returns random integer between minimum and maximum range
  25.      */
  26.     public static int getRandomInteger(int maximum, int minimum){
  27.         return ((int) (Math.random()*(maximum - minimum))) + minimum;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement