• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Random / swtich operator

 
Marky Mark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9257
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic