Dice Roll

Collapse Content

These challenges will involve using if-then-else loops. Here's a simple challenge to get started.

You're programming a backgammon game, and are working on the dice roll method. Given two ints, return their sum. However, if the two numbers are the same, return double their sum.


Image from Wikipedia


Return the sum (or double sum) of two ints, as above.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.


  • Haha, LOL! I can't solve it now, it's funny! But I solve the problem some other way, I created my own version of code with another logic:

    import java.util.Scanner;

  • there some kind of mistake? Method contain two params, why does it can calculating with only one param?????

  • if a and b are the same, then its essentially one parameter. (a+b) * 2 is the same as a * 4

  • Dude can someone please post the answer..

  • Really simple stuff. For those of you stuck on this, remember order of operations and == other than that this should be a piece of cake with some ice cream.

  • I copied the answer in and it was still incorrect... what dafuq this site has bugs and it's teaching me how to code? what is this.

        return a * 4;
        return a+b;
  • @Cherry, you left out the closing curly bracket of the method when you copied the code.

  • The problem is with the last set of parameters. It is 2 and 2 and expects an 8, when in fact it should expect a 4.

  • Very interesting. I went further to add an extra if statement that allows only numbers between 1 and 6.

  • here's mine :

    import java.util.Scanner;

    public class Main {

    static int doStuff(int a, int b){
        //your code here
                return a+b;
                return (a+b)+(a+b);
  • I do it. It was interesting.

  • Please can someone help. I can't figure out what I'm doing wrong in this question.
    Here is my code
    import java.util.Scanner;

    public class DiceRolling {

  • this is so simple...use the same logic as you used in earlier challange of if else.....
    if (a==b){
    return (a+b)*2;
    return (a+b);

  • Random rand = new Random();

        int a = rand.nextInt(7);
        int b = rand.nextInt(7);
Contact Us
Sign in or email us at [email protected]