Quote:
Originally Posted by Y0u_G0t_Pwn3d
I've been programming in Java for about 4 days now, 2 days ago I was doing a programming exercises that came with the free book that I got off the internet. It was to simulate dice rolls and see how many rolls it took to get snake eyes. I set at my laptop for 2 hours trying to figure it out. Then today I went back and I realized I had to use a while loop. -Facepalm-
|
Code:
import java.lang.reflect.*;
class DiceTest {
private static int random() {
return (int)(Math.random() * 6);
}
public static void main(String[] args) {
int tries = 0;
while(true) {
tries++;
int dice1 = random();
int dice2 = random();
if((dice1 == 1) && (dice2 == 1)) {
System.out.println("Snake eyes on try #" + tries);
break;
}
}
}
}
That took you over 2 hours? Lol..
Let's see...I got started with HTML when I was in 4th grade because I wanted to make my own website (I have no idea why). In 5th grade, I got a book on game programming which was with blitz basic (a waste of my time, in which I learned nothing). In 6th grade, I got familiar with Java with RSPS (I was so bad, I couldn't create a HelloWorld Program on my own >__<). Then November of last year I started up with Java again. I learned stuff pretty quickly, also learned some C# (very similar to Java), as well as XML (markup, not programming language), php (scripting, not programming), and here I am now.