public String roll()
        Random generate = new Random();
        int diceRoll; 
        int firstNum;
        int secondNum;
        boolean winner = false;

            for (int x=1; x<=3; x++)
                firstNum = generate.nextInt(6)+1;
                secondNum = generate.nextInt(6)+1;
                diceRoll = firstNum + secondNum;
                System.out.println("Roll number " + x + " was " + diceRoll);

                if(userNum == diceRoll)
                    winner = true;

                System.out.println("\nYou win!! Congratulations");
                System.out.println("\nYou lose");

        return roll;

When I run This class on my driver class at the end of the whole loop I get my numbers and all but I also get the word null at the end.
Just like this:

Roll number 1 was 6
Roll number 2 was 8
Roll number 3 was 2

You win!! Congratulations

Recommended Answers

All 2 Replies

Where is the println statement that prints out the null?
What is the value of the roll variable that is returned by the roll() method?

Line 34, you are returning roll variable but you didn't have anything to do with the variable inside the method. The method is supposed to build up a String and return it?

Be a part of the DaniWeb community

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