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
¿cuáles son los usos que se le pueden dar a una bicicleta?
riadik2000 [5.3K]

Answer:

pues de decoracion las llantas de columpios y los cuernos de antenas de tele okey no me presiones estoy en clase y acabo de hacer 11 ejercicios y acaba de empezar ok

7 0
3 years ago
___are designed to infect and cause damage to operating system files, computer registry, and other locations on the motherboard
Firlakuza [10]

Answer:

Viruses

Explanation:

virusues are designed to infect and cause damage to operating system files, computer registry, and other locations on the motherboard

3 0
3 years ago
(True/False) Utilizing a higher bandwidth can support a larger volume of data (in bits per second) to be transmitted than a lowe
lions [1.4K]

Answer:

True

Explanation:

Bandwidth refers to the maximum data transfer rate across the communication media it refers to the amount of information sent for unit time and it's not related to the speed at which data is transferred (latency) but rather the amount of information. As an analogy imagine a full-pipe, the width of the pipe is related to the amount of water per unit time across the pipe (bandwidth).

3 0
3 years ago
Read 2 more answers
What name is used to denote a common field that exists between two tables, but is also the primary key for one of the tables??"
Diano4ka-milaya [45]

Answer:

b. foreign key

Explanation:

In the database world, a foreign key is a field on one table and a primary key for another table. The purpose of a foreign key is to provide linkages between two or more tables. Given two tables A and B, and making A the point of reference, a primary key is a field that is unique in A while a foreign key is unique in B.

On another hand, a composite primary key is a combination of two or more fields/columns on database table that can be used to uniquely identify each row in the table.

In the database lingua, what we have is a unique key not a distinct key, though the two words are similar in meaning.

A duplicate key is used when an information may be repeatedly entered on a table.

So the correct option is a foreign key.

4 0
4 years ago
Which would be the best and worst answer choices?
jeyben [28]

Answer:

option 3

Explanation:

4 0
3 years ago
Other questions:
  • T<br> F<br> 5.<br> You can save presentations in PDF and XPS formats.
    14·1 answer
  • Help with some questions. Thank you!
    14·1 answer
  • If you have a long title for a table and need it to span several cells, you can use A. Merge Cells. B. Split Cells. C. Insert Co
    5·1 answer
  • Var faceS = 100; var mouthS = 30; ellipse(200, 200, faceS, faceS); ellipse(200, 220, mouthS, mouthS); How wide is the second ell
    12·1 answer
  • What statement best describes operating systems?
    12·1 answer
  • When doing a Risk assessment, what is one of the most important things to do?
    8·2 answers
  • PLZZ HELP
    11·1 answer
  • WILL GIVE BRAINLIEST! 20 POINTS! PLZ HELP!
    14·2 answers
  • What is the first step in finding a solution to a problem?
    9·2 answers
  • What is pseudocode? O A way of describing a set of instructions in text form using plain english O A diagrammatic representation
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!