Java Genesis

Hints for Chapter 4: Control Constructs

Problem 1: hint 2

Here is our code for the class WinToss:


   public class WinToss {
	
	/*
	Toss a coin to win!
	*/
	
	public static void main (String [ ] args) {
	   int num1 = (int)(6*Math.random()) + 1;
	   int num2 = (int)(6*Math.random()) + 1;
	   if (num1 > num2)
		System.out.println("first player wins");
	   else
		System.out.println("second player wins");
	}
   }

Previous Hint