# Dice Roll

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

### Challenge

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

Alternatively, you can try out Learneroo before signing up.

• #### /users/1550

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;

• #### Amboss

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

• #### David

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

• #### Greg

• #### Krondo

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.

• #### Cherry Chen

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.

``````if(a==b){
return a * 4;
}
else{
return a+b;
}
``````
• #### Learneroo

@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.

• #### chima oscar

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

• #### TJ Duarte

here's mine :

import java.util.Scanner;

public class Main {

``````static int doStuff(int a, int b){
if(a!=b)
{
return a+b;
}
else
{
return (a+b)+(a+b);
}
}
``````
• I do it. It was interesting.

• #### Mony Jang

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 {

• #### sumo

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

• #### Janusz

Random rand = new Random();

``````    int a = rand.nextInt(7);
int b = rand.nextInt(7);
``````
• #### ddds

check the logic this is correct one :
if(a==b){
return (a+b)+(a+b);
}
else{
return a+b;
}

• #### Dixit

showing error

• #### Dheeraj Parmar

#include
using namespace std;

int func(int a , int b){
int sum=a+b;
if(a != b){
return sum;

``````}
else if(a == b){
return sum*2;
}
return 0;
``````

}
int main(){
int a=0;
int b=0;
cin>>a>>b;
cout<<func(a,b);

}

• #### Roger

let a = 0 + Math.floor(Math.random()* 6) + 1;
let b = 0 + Math.floor(Math.random()* 6) + 1;

function diceRoll() {
let sum = a + b;
if (a == b) {
return sum *= 2
} else {
return sum
}
}