Java Reference
In-Depth Information
public String toString() {
return name;
};
private static Random rnd = new Random();
public static CoinSide flip() {
return rnd.nextBoolean() ? HEADS : TAILS;
}
public static void main(String[] args) {
System.out.println(flip());
}
}
In release 5.0 and later releases, it is natural to write CoinSide as an enum type:
public enum CoinSide {
HEADS, TAILS;
public String toString() {
return name().toLowerCase();
}
// flip and main same as in 1.4 implementation above
}
 
 
Search WWH ::




Custom Search