Advertisements

Write a program SumOfTwoDice.java that prints the sum of two random integers between 1 and 6 (such as you might get when rolling dice).

//2-18-14
//TEST ** (double star) program
import java.lang.Math;

public class DicerollTEST{
public static void main(String[] args) {
int SIDES = 6;                                                                                //declares there 6 sides on a die and int SIDES
int a = 1 + (int) (Math.random() * SIDES);                       //Gives the random roll to one die
int b = 1 + (int) (Math.random() * SIDES);                      //Gives the random roll to the second die
int sum = a + b;                                                                            //Adds the sum of the two dice
System.out.println(sum);                                                       //Prints the sum of the 2 dice
}
}

Advertisements

About Rant4u

A Revolution in Social Networking

Posted on February 18, 2014, in #social media, Java programming and tagged , , , , , , , . Bookmark the permalink. Leave a comment.

Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: