Question

Using Java, write a program that rolls 3 20-sided die and adds them together. Make sure...

Using Java, write a program that rolls 3 20-sided die and adds them together. Make sure to display their output so you can use it in your Dungeon and Dragons game.

Sample output 1: You rolled a 60.

Sample output 2: You rolled a 3.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Random;

public class DungeonAndDragons {

    public static void main(String[] args) {
        Random random = new Random();
        int d1 = 1+random.nextInt(20);
        int d2 = 1+random.nextInt(20);
        int d3 = 1+random.nextInt(20);
        System.out.println("You rolled a " + (d1+d2+d3) + ".");
    }
}
Add a comment
Know the answer?
Add Answer to:
Using Java, write a program that rolls 3 20-sided die and adds them together. Make sure...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT