External Exam Download Resources Web Applications Games Recycle Bin

coin toss


//save as coinToss.java
import java.util.Random;
public class coinToss {
    public static void main(String[] args) { 
        Random seed = new Random();
        //generate a random number between 1 and 2:
        int  roll = seed.nextInt(2) + 1;
        switch (roll)
          {
          case 1 :
            System.out.println("Heads");
            break;
          case 2 :
            System.out.println("Tails");
            break;
          }
    }
}