Hello All,
I just started learning java at home .I am getting an error message".java:8: error: cannot find symbol
int randomNum = (int) (Math.Random() *5);"

Could you please help me on the same?

Here is my java code:
class SimpleDotComGame{
    public static void main(String [] args){
        int numOfGuesses = 0;
        GameHelper helper = new GameHelper();
        //
        SimpleDotCom theDotCom = new SimpleDotCom();
        int randomNum = (int) (Math.random() *5);
        int [] locations = {randomNum,randomNum+1,randomNum+2};
        theDotCom.setLocationCells(locations);
        boolean isAlive = true;
        while (isAlive == true){
            String guess = helper.getUserInput("enter a number");
            String result = theDotCom.checkYourself(guess);
            numOfGuesses++;
            if(result.equals("kill")){
                isAlive = false;
                System.out.println("You took " + numOfGuesses+ "guesses");
            }
            }
        }
    }

Recommended Answers

All 4 Replies

That message does not correspond to the code you posted, so that's useless.
Anyway - check your capitalisation... the method name is random not Random

ps: You will get a faster resonse by posting Java questions in the Java forum.

Thanks James. I did the changes in my code as you suggested  (int randomNum = (int) (Math.random() *5);). however still I am getting same error message.
"F:\Java Program>javac SimpleDotComGame.java
SimpleDotComGame.java:7: error: cannot find symbol
                int randomNum = (int) (Math.random() *5);
                                           ^
  symbol:   method random()
  location: class Math
1 error"

I'm baffled. That code is valid.
Is it possible that you have created your own class called Math at some point? If so you could try referencing the right class explicitly...
int randomNum = (int) (java.lang.Math.random() *5);

Thanks James . You are great. now code is working as expected. Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.