wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Random / swtich operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Random / swtich operator" Watch "Random / swtich operator" New topic
Author

Random / swtich operator

Marky Mark
Greenhorn

Joined: Nov 12, 2003
Posts: 4
Hello, i just posted a question before, i thought it would solve my problem, but if anything it just confused me. The following code was written by myself. The aim of this program is to genarate a random letter, i have just done it between a-e. As you can see, its not complete, i dont know what i need to add to get it to work -
- can anyone help me by adding to the code ? ? I think i need to do a variable convertion, but i aint a clue !! please help !!
import javax.swing.JOptionPane;
public class RandomLetter {
public static void main (String args[]) {
int rollOfDice;
String Random1,output;
char Random2;

//genarate a random number between 1 and 5 inclusive
rollOfDice = (int)(Math.random()*5)+1;
output = "The letter is "+rollOfDice";


switch(letter) {
case 1:
output="The letter is a";
break;
case 2:
output="The letter is b";
break;
case 3:
output="The letter is c";
break;
case 4:
output="The letter is d";
break;
case 5:
output="The letter is e";
break;
} // end of switch

//print messgae
JOptionPane.showMessageDialog(null,output,"Random Number Demo",
JOptionPane.INFORMATION_MESSAGE);

System.exit(0);
}
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

That code works fine once you fix the two relatively obvious compile errors. Are you CERTAIN you wrote this code yourself?
[ November 12, 2003: Message edited by: Joe Ess ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Random / swtich operator