1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Hitman42 [59]
3 years ago
14

Create a game that rolls two dies (number from 1 to 6 on the side) sequentially for 10 times (use loop). If at least once out of

10 times the sum of two random numbers is equal to 10, you win, else you loose. You will need to get your own method getRandom(int n) that generates a random number, see below (you can modify it as needed), a loop, and IF statement in the loop that checks if a sum of two random numbers is 10 or not.
Please start your program as follows, similar to what we did in class:
import java.util.Random;
public class UseRandom{
//your method getRandom() is here below, n is a range for a random number from 0 to n
public int getRandom(int n)
{
Random r=new Random();
int rand=r.nextInt(n);
return rand;
}
//code continues here, don't forget your main() method inside the class, and making your own object in main() using "new" keyword.
Computers and Technology
1 answer:
Alex73 [517]3 years ago
8 0

Answer:

Explanation:

The following code is written in Java and loops through 10 times. Each time generating 2 random dice rolls. If the sum is 10 it breaks the loop and outputs a "You Win" statement. Otherwise, it outputs "You Lose"

import java.util.Random;

class Brainly {

   public static void main(String[] args) {

       UseRandom useRandom = new UseRandom();

       boolean youWin = false;

       for (int x = 0; x<10; x++) {

           int num1 = useRandom.getRandom(6);

           int num2 = useRandom.getRandom(6);

           if ((num1 + num2) == 10) {

               System.out.println("Number 1: " + num1);

               System.out.println("Number 2: " + num2);

               System.out.println("You Win");

               youWin = true;

               break;

           }

       }

       if (youWin == false) {

           System.out.println("You Lose");

       }

   }

}

class UseRandom{

   public int getRandom(int n)

   {

       Random r=new Random();

       int rand=r.nextInt(n);

       return rand;

   }}

You might be interested in
Why does a HTML seen to work even when its broken? why does the code sometimes turn pink?
OverLord2011 [107]

the reason HTML seems to work even if it has syntax errors is due to browser having built in ways to parse the code meaning it will still show but most likely look way different then you would want.

the code may turn pink due to syntax errors

5 0
3 years ago
What is the purpose of the product backlog refinement
BigorU [14]

Answer:

A

Explanation:

6 0
3 years ago
Read 2 more answers
Research shows that a passive close to a cover letter leads to more interviews. Please select the best answer from the choices p
Alchen [17]
The answer is False.

According to research, a passive close doesn't lead your cover letter to have more interviews. In writing the closing part of your cover letter, it is easy to have a passive sentence but it sounds like less confidence to the employer. The last part of the cover letter should contain strong content to give an impression to the person who reads.
6 0
3 years ago
Read 2 more answers
(70 points, ip address)If anyone can solve all these questions correctly
Mrac [35]

Answer:

its c

Explanation:

4 0
3 years ago
EXERCISE
nirvana33 [79]

Answer:

1. True

2. True

3. False

4. True

5. True

8 0
2 years ago
Other questions:
  • A measure of the twisting or rotational force that an engine can produce is called
    12·1 answer
  • This type of technology does not come with a keyboard or mouse for input
    11·2 answers
  • Janice, who is 15, posts post a picture of herself drinking alcohol and making an obscene gesture on her social network page. wh
    15·2 answers
  • What is the simplest way to permanently get rid of a unwanted file
    12·1 answer
  • What command prompts should be used to assign an IP address to:
    9·1 answer
  • Which of the following technologies is the best choice to convey urgent and highly sensitive information?a. Telephone b. Fax Let
    12·1 answer
  • You are configuring two PCs for your network, PC-A is given an IP address of 192.168.1.18 and PC-B is given an IP address of 192
    15·1 answer
  • Write a python program that will read a number (num) and display all the numbers divisible by 3 or 5
    15·1 answer
  • Consider the following method, which is intended to count the number of times the letter "A" appears in the string str.
    13·1 answer
  • How do i unblock a website on a school computer if a school blocks it?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!