| 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: 8259
|
|
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]
|
 |
 |
|
|
subject: Random / swtich operator
|
|
|