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
Alinara [238K]
3 years ago
14

Write a Java program that generates a random number between 0 and 50. Then, the program prompts for guesses until the user is co

rrect, or has made 10 wrong guesses. After each guess, the program indicates whether the guess was too high, too low, or correct. Once the round has ended, either by a correct guess or by using up the 10 guesses, the program displays the current status. Enter an integer number ( 0 to exit): 3241 3241 has 4 digits. Sum of digits of 3241 is 10. Enter an integer number ( 0 to exit): 264 264 has 3 digits. Sum of digits of 264 is 12. Enter an integer number ( 0 to exit): -12 -12 has 2 digits. Sum of digits of -12 is -3. Enter an integer number ( 0 to exit): 0 End. Enter a positive integer between 0 and 9: -3 Invalid input number. Enter a positive integer between 0 and 9: 15 Invalid input number. Enter a positive integer between 0 and 9: 5 0 !

Computers and Technology
1 answer:
tino4ka555 [31]3 years ago
5 0

Answer:

Here is the JAVA program:

import java.util.Scanner;  //to accept input from user

public class Main {   //class name

   public static void   GuessTheNumber()      {  //method to guess the number

       Scanner input = new Scanner(System.in);   //creates Scanner object to accept input from user

       int number = (int)(50 * Math.random()) ;   //generates random number from 0 to 50

       int trials = 10;  //allows 10 trials to user to guess the number

       int i, userGuess;  //stores user guess

       System.out.println("Guess a number between 0 to 50");  //prompts user to guess a number between 0 to 50  

       for (i = 0; i <trials; i++) {  //allows user to keep guessing in 10 trials

           System.out.println("Enter your guess: ");   //prompts user to enter a number as a guess

           userGuess = input.nextInt();  //reads users entered number(guess)

           if (number == userGuess) {  //if users guess is correct

               System.out.println("Congratulations! The guess is correct!");  //displays congratulatory message

               break;              }  //the loop breaks after correct guess is made

           else if (number>userGuess) {  //if user guess is less than correct number

               System.out.println("Too low");             }  

           else if (number<userGuess) {  //if user guess is greater than correct number

               System.out.println("Too high");            }          }    

       if (i == trials) {  //if user has made 10 wrong guesses

           System.out.println("You exceeded 10 trials!");

           System.out.println("The correct number was " + number);          }      } //displays the correct number if user made 10 wrong guesses

 

   public static void main(String arg[])      {     //start of main method

       GuessTheNumber();      }  } //calls method to start the guessing game

Explanation:

The program prompts the user to enter a guess and it uses random() method to generate randoms numbers from 0 to 50. The loop keeps iterating and prompting the user to enter a guess until the limit of number of trials exceeds. The trials are set to 10 so the user can guess a number in 10 tries. If the user guesses a number that is higher than the correct guess then the program indicates that the guess is too high by displaying a message "too high" and if user guesses a number that is lower than the correct guess then the program indicates that the guess is too low by displaying a message "too low". If user makes 10 wrong guess then the program displays the correct guess and ends. The screenshot of the output is attached.

You might be interested in
To which type of domain does information on wikis belong?
Misha Larkins [42]

Answer:

Hope it helps you. ^_^

Explanation:

".info (TDLs)" domain.

3 0
3 years ago
Examine these statements about computer software. Which one is false? a Computer software is a collection of coded instructions.
Gnesinka [82]

Answer:

d Computer software used to control a work cell is fundamentally different to business software.

Explanation:

A computer software used to control a work cell is not fundamentally different from a business software. They are different in terms of what they do or the problem they solve or different coded instructions that the computer executes for each of them or maybe different computer languages and hardware requirements. However they are not different fundamentally as they are both computer programs that are based on computer algorithms and code languages or instructions that the computer executes to solve a particular problem.

7 0
4 years ago
How would you define the term technology
ivanzaharov [21]
Technology is a way that most people are communicating now a days, whether it be with a phone, computer, etc. It’s is also how businesses can do things like making ad’s.

Not great at explaining things but you can probably make it sound a lot better by adding in your own word!
5 0
3 years ago
When you point to defined styles in the cell styles gallery, you can see the formatting that will be used when you apply each st
Dvinal [7]
Hello  <span>Missthang2456 </span>

Question: <span>When you point to defined styles in the cell styles gallery, you can see the formatting that will be used when you apply each style?


Answer: This is true

Hope This Helps!
-Chris</span>
4 0
3 years ago
Consider the following C++ program. #include using namespace std; int main() { cout &lt;&lt; "Hello World " return 0; } In the c
Ray Of Light [21]

Answer:

Compiler.

Explanation:

Actually there are two things missing in the code first is the header file.There is only # include no filename is there like<iostream>,,bits/stdc++.h> etc.cin ,cout will not work until iostream is included in the program.After including the header properly the missing semicolon will be caught by the compiler.The error will be as following:-

expected ';' before return.

4 0
3 years ago
Other questions:
  • DOES ANYONE KNOW HOW TO CHAGE THE IP ON A COMPUTER?
    8·1 answer
  • Which situation is an example of? "relational context" in the transactional model of? communication?
    12·1 answer
  • All digital images are made up from varying rectangles of color, called _____________.
    6·2 answers
  • A user is connecting to an e-commerce server to buy some widgets for a company. the user connects to the site and notices there
    10·1 answer
  • Diagnosing is solving the problem, and trouble shooting is figuring out what the problem is.
    15·1 answer
  • DeShawn uses Google Ads. He wants to enable website call conversion tracking so he can see how his current ad campaign is drivin
    12·1 answer
  • Create a goal seek analysis to determine what the price should be to generate demand of 2,625,000 tablets given that the supplie
    10·1 answer
  • an images scanned from a CD cover does not have to be cited because you didn't find the image on the internet True or false
    6·1 answer
  • The router can deliver packets directly over interfaces 0 and 1 or it can forward packets to Routers R2, R3, or R4. Describe wha
    10·1 answer
  • Explain the complement of a number along with the complements of the binary and decimal number systems.why is the complement met
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!