Write a program that rolls a dice (but hide the number from player) and then ask user enter a number in range of 1 - 6. If player enters same number of computer rolled, then the player earns $10. If player enters a number that is smaller or larger by 1, then the player earns $3. If player enters a number that is smaller or larger by 2, then the player earns $1. Player has to pay $3 dollar to play once. Make a MatchDice game.

Recommended Answers

All 7 Replies

Do you have any java programming questions?

int die1;
int die2;
int roll;

die1 = (int)(Math.random()*6) + 1;
die2 = (int)(Math.random()*6) + 1;
roll = die1 + die2;

Do you have any questions?

but how can i let the computer choose ? @ 1st

how can i write it in the Eclipse

how can i let the computer choose ?

What is the computer supposed to choose?
If you want a random choice, use the Random class (or Math class's random()) to generate random numbers.

how can i write it in the Eclipse

well ... typing your code in eclipse, rather than in a post here would be a good start.
I don't really see anything wrong with your code above, so what exactly is it what you need help with?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.