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
Who is maintain data and time of computer?​
stich3 [128]

Answer:

Explanation:

Data servers like ntp pool dot org give free time data to many Linux computers. Windows computers use the Microsoft Time Servers. So it depends on which computer, its operating system, and which server it chooses to use.

NTP server stands for Network Time Protocol

7 0
3 years ago
A device used to measure the pressure of an enclosed gas is a manometer.<br> a. True<br> b. False
Taya2010 [7]
Its true, check it out here 

manometer
nounan instrument for measuring the pressure acting on a column of fluid, consisting of a U-shaped tube of liquid in which a difference in the pressures acting in the two arms of the tube causes the liquid to reach different heights in the two arms.
4 0
3 years ago
_____ is a group of Internet-based applications that build on the ideological and technological foundations of Web 2.0, and that
lutik1710 [3]

Answer: Social media

Explanation:

 Social media is defined as the group of the internet based various applications that basically build on the foundation of  technological and ideological of the web 2.0. It basically allow the exchange of the user content and creation.

It is the most flexible platform that enable the users with the huge experience. It is also known as free and open source platform. It basically contain the various content that are algorithm driven and machine learning.

 

3 0
3 years ago
Remember to check the on your vehicle first to see if a repair is covered by the manufacturer.
krok68 [10]

Answer:

insurance or warranty

Explanation:

It should be insurance because insurance can cover things like car repairs and other things that goes wrong. warranty could work too because it kind of means the same thing.

5 0
4 years ago
What are possible consequences for cyberbullying?
BaLLatris [955]

Answer:

Possible consequences for cyber bullying include depression, isolation and illness

Explanation:

The reason for this is when a person is hurt there body tends to go through things to make them feel a certain way about things.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Wendy is an attacker who recently gained access to a vulnerable web server running Microsoft Windows. What command can she use t
    9·1 answer
  • What is last mile in VOIP
    13·1 answer
  • Commands are organized into tabs on the A. Ribbon. B. Quick Access toolbar. C. Status bar. D. ruler.
    13·2 answers
  • A machine on a 10 Mbps network is regulated by a token bucket algorithm with a fill rate of 3 Mbps. The bucket is initially fill
    12·1 answer
  • Will technology be the destruction or salvation of human-kind
    13·2 answers
  • Which of the following are used to classify plutons
    14·1 answer
  • What is string literal in Java?
    5·1 answer
  • I need help 50 points and brainiest if you answer
    10·2 answers
  • The best presentations try to include as much text as possible on each slide true or false ​
    13·1 answer
  • web analytics can tell you many things about your online performance, but what can analytics tools not tell you​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!