SnakeEyesCount.java.xhtml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * <https://y.st./>
  4. * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org./licenses/>.
  18. **/
  19. $xhtml = array(
  20. 'title' => 'SnakeEyesCount.java',
  21. 'subtitle' => 'Written in <span title="Programming 1">CS 1102</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on 2017-04-19',
  22. 'copyright year' => '2017',
  23. 'body' => <<<END
  24. <h2>Source code:</h2>
  25. <blockquote>
  26. <pre><code>/*
  27. * Copyright (C) 2017 Alex Yst
  28. *
  29. * This program is free software: you can redistribute it and/or modify
  30. * it under the terms of the GNU General Public License as published by
  31. * the Free Software Foundation, either version 3 of the License, or
  32. * (at your option) any later version.
  33. *
  34. * This program is distributed in the hope that it will be useful,
  35. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. * GNU General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU General Public License
  40. * along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
  41. */
  42. package snakeeyescount;
  43. /**
  44. *
  45. * @author Alex Yst
  46. */
  47. public class SnakeEyesCount {
  48. public static void main(String[] arguments) {
  49. int count = 0;
  50. int die0;
  51. int die1;
  52. for(int i = 0;i &lt; 1000;i++) {
  53. do {
  54. count++;
  55. die0 = (int)(Math.random()*6)+1;
  56. die1 = (int)(Math.random()*6)+1;
  57. } while(die1 != 1 || die2 != 1);
  58. }
  59. System.out.print(((float)count)/1000 + &quot;\\n&quot;);
  60. }
  61. }</code></pre>
  62. </blockquote>
  63. <h2>Output:</h2>
  64. <h3>Time 0</h3>
  65. <blockquote>
  66. <pre>run:
  67. 38.649
  68. BUILD SUCCESSFUL (total time: 0 seconds)</pre>
  69. </blockquote>
  70. <h3>Time 1</h3>
  71. <blockquote>
  72. <pre>run:
  73. 35.446
  74. BUILD SUCCESSFUL (total time: 0 seconds)</pre>
  75. </blockquote>
  76. <h3>Time 2</h3>
  77. <blockquote>
  78. <pre>run:
  79. 35.604
  80. BUILD SUCCESSFUL (total time: 0 seconds)</pre>
  81. </blockquote>
  82. <h3>Time 3</h3>
  83. <blockquote>
  84. <pre>run:
  85. 36.36
  86. BUILD SUCCESSFUL (total time: 0 seconds)</pre>
  87. </blockquote>
  88. <h3>Time 4</h3>
  89. <blockquote>
  90. <pre>run:
  91. 36.916
  92. BUILD SUCCESSFUL (total time: 0 seconds)</pre>
  93. </blockquote>
  94. END
  95. );