import java.util.*;
class HelloWorld {
public static void main(String[] args) {
int rn = 1 + (int)(Math.random()*5);
System.out.println(rn);
if (rn == '1') {
System.out.println("I am convinced that He (God) does not play dice.");
}
else if (rn == '2') {
System.out.println("Reality is merely an illusion, albeit a very persistent one.");
}
else if (rn == '3') {
System.out.println("The only thing that interferes with my learning is my education.");
}
else if (rn == '4') {
System.out.println("Imagination is more important than knowledge.");
}
else if (rn == '5') {
System.out.println("The secret to creativity is knowing how to hide your sources.");
}
}
}
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein
Several things go wrong: you are checking an int with a string, fails. And the random is an arbitrary number somewhere between:
0,00000000000000001 and 0,9999999999999999999
So to get a random integer number between 1 and 6 use this: Math.Floor(Math.Random() * 5); which returns an int value.
Oh casting the Math.Random ( Double i believe ) by default makes it 0.
It sounds like the other posters have touched on the biggest problems, but I wanted to tell you about one of the most powerful debugging features of Java (outside of an actual debugger), which really more languages should add (C# I am looking at you lol): Assertions! They are almost like little unit tests you can add to your code which will throw exceptions (aka errors) if what you put in the assertions are not true. You don't even have to remove them from your finished application, because they don't do anything unless you explicitly turn them on in the compiler! Assertions are very powerful and well-worth learning more about! Below is Oracle's tutorial on how to use them:
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
int rn = 1 + (int)(Math.random()*5);
if (rn == 1) {
System.out.println("I am convinced that He (God) does not play dice.");
}
else if (rn == 2) {
System.out.println("Reality is merely an illusion, albeit a very persistent one.");
}
else if (rn == 3) {
System.out.println("The only thing that interferes with my learning is my education.");
}
else if (rn == 4) {
System.out.println("Imagination is more important than knowledge.");
}
else if (rn == 5) {
System.out.println("The secret to creativity is knowing how to hide your sources.");
}
}
}
P.S. @jackolantern I plan on reading up on it but im just getting into basic I/O so its gonna take me a little bit before I can get to it. Thanks for the link though!
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein