# Calling a toss dice method

• August 18th, 2013, 01:33 PM
salmayoussef
Calling a toss dice method
I wrote a method to toss dice (in it, I used another method--the rollDice method), and I want to know how to call it in the main method, because I'm completely confused on that section! >:P Any help would be great! Here's the method:
Code :

```//Toss dice public static int tossDice(int sum){ Random rand = new Random(); int tries = 0; while (sum != 7 && sum != 11) { // Roll the dice method int roll1 = rollDice(); int roll2 = rollDice(); sum = roll1 + roll2; System.out.println(roll1 + " + " + roll2 + " = " + sum + "."); tries++; } System.out.println("You won after " + tries + " tries!"); System.out.println("You rolled a sum of " +sum+ "."); return sum; }```

Thank you!
• August 18th, 2013, 01:44 PM
GregBrannon
Re: Calling a toss dice method
You call rollDice() just fine in the tossDice() method. I don't understand what you're asking about calling rollDice() in or from the main() method. Why would you? Have you written rollDice()? Where is it?
• August 18th, 2013, 02:00 PM
salmayoussef
Re: Calling a toss dice method
I've written rollDice() already! But that's not the problem. What I've posted is a method I've written on my own. My assignment asks me to write my own method (done that) and call it in the main method. I'm asking how I'd call the method I've written above. What would I write to call it?
• August 18th, 2013, 03:34 PM
GregBrannon
Re: Calling a toss dice method
Something like:
Code java:

```public static void main (String[] args) { // define sum, . . .   // . . . and then call the method: tossDice( sum ); }```