File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Random / swtich operator

Marky Mark

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";
case 2:
output="The letter is b";
case 3:
output="The letter is c";
case 4:
output="The letter is d";
case 5:
output="The letter is e";
} // end of switch

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

Joe Ess

Joined: Oct 29, 2001
Posts: 9189

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 ]

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Random / swtich operator
It's not a secret anymore!