fork download
  1. class Coin
  2. {
  3. private final int HEADS = 0;
  4. private int face;
  5.  
  6. public Coin()
  7. {
  8. flip();
  9. }
  10. public void flip()
  11. {
  12. face = (int)(Math.random()*2);
  13. }
  14. public boolean isHeads()
  15. {
  16. if(face==HEADS)
  17. return true;
  18. else
  19. return false;
  20. }
  21. public String toString()
  22. {
  23. if(isHeads())
  24. return "Heads";
  25. else
  26. return "Tails";
  27. }
  28.  
  29. public static void main (String[] args) throws java.lang.Exception
  30. {
  31. Coin penny = new Coin();
  32. Coin quarter = new Coin();
  33. int count1 = 0;
  34. int count2 = 0;
  35. do
  36. {
  37. penny.flip();
  38. quarter.flip();
  39. if(penny.isHeads())
  40. {
  41. count1++;
  42. }
  43. if(quarter.isHeads())
  44. {
  45. count2++;
  46. }
  47. }
  48. while(count1 != 10 || count2 != 10);
  49. if(count1 == 10)
  50. {
  51. System.out.println("Penny won!");
  52. }
  53. if(count2 == 10)
  54. {
  55. System.out.println("Quarter won!");
  56. }
  57. }
  58. }
Time limit exceeded #stdin #stdout 5s 2317312KB
stdin
Standard input is empty
stdout
Standard output is empty