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
hichkok12 [17]
3 years ago
8

(JAVA programming) Guess Number program

Computers and Technology
1 answer:
amm18123 years ago
4 0

Answer:

The following are the program in the Java Programming Language.

import java.util.Random; //import package

import java.util.Scanner; //import package

//define a class

public class GuessNumber {

   //define a main method

   public static void main(String[] args)

   {

       //create object of the Scanner class

       Scanner cs = new Scanner(System.in);

       //print message

       System.out.println("Guess the secret number\n");

       //print message

       System.out.print("Enter the maximum value for the secret number: ");

       //get input in the integer variable through scanner class object

       int maxNum=cs.nextInt();

       //create object of the Random class

       Random ran = new Random();

       //declare an integer variable that store random number  

       int guessed = 1+ran.nextInt(maxNum);

       //set the while loop

       while (true)  

       {

           //print message

           System.out.println("\nA new secret number has been chosen.");

           //set two integer variables to 0

           int user = 0;

           int count = 0;

           //set the while loop

           while (user != guessed)  

           {

               //print message

               System.out.print("Enter guess: ");

               //get input in the variable from user

               user = cs.nextInt();

               //increment the variable by 1

               count++;

               //check that the user is less than guessed

               if (user < guessed)  

               {

                   //then, print message

                   System.out.println("low, try again.");

               }

               //check that user is greater than guessed

               else if (user > guessed)  

               {

                   //then, print message

                   System.out.println("high, try again");

               }

           }

           //print message with count

           System.out.println("You won in " + count + "!");

           //print message and get input

           System.out.print("\nPlay again? (Y/N)");

           cs.nextLine();

           String again = cs.nextLine();

           //check that input is y

           if(again.equalsIgnoreCase("y"))

           {

               //then, loop again iterates

               continue;

           }

           //otherwise, loop is break

           else{

               break;

           }

       }

   }

}

Explanation:

<u>The following are the description of the program</u> :

  • Firstly, we import the required packages and define the class 'GuessNumber'.
  • Inside the class, we create the object of the scanner class and the random class then, get input from the user through scanner class object and generate random number through the random class object.
  • Then, set the while infinite loop in which we declare two integer data type variables and assign them to 0 then, set while loop inside the infinite loop that iterates when the 1st variable is not equal to the second one then, get input from the user through scanner class object.
  • Then, check that input number is less than the random number then, print message otherwise, again check that input number is greater than the random number then, print message or if both numbers are equal then print the message with the count.
  • Finally, the program asks for play again, if the input is 'y' then, infinite loop again iterates otherwise the infinite loop is break.
You might be interested in
list three quantitative characteristic properties of water explain why they are considered characteristic
tia_tia [17]

Answer:

The three quantitative characteristic properties of water is explained below in detail.

Explanation:

The three quantitative components of water incorporate the following:

1.Freezing point:

The water has a freezing point of 0 degrees Celsius.

2. Boiling point:

The water has a boiling point of 100 degrees Celsius.

3. Melting point:

The melting point of ice is 0 degrees Celsius.

These properties are all uncommon to water. Being uncommon means that these characteristics are only noticeable in water; hence, they can be beneficial in recognizing such a substance.

5 0
3 years ago
A government agency is getting rid of older workstations. The agency will donate these workstations, along with other excess com
algol [13]

The simplest ways are being used to help eliminate the previously stored data, by deleting hard disc storage facilities with the same data wherever that used a sequence of all zeros.

<h3>What is a hard disc?</h3>

The "DoD Standard" is a term used during the data sanitizing industry and refers to DoD 5220.22-M, and the further discussion can be defined as follows:

The simplest ways are being used to help eliminate the previously stored data, by deleting hard disc storage facilities with the same data wherever that used a sequence of all zeros.

The sparging eliminates statistics to entirely delete the gravitational flux from electronic media.

Hard drives as well as other data storage devices, for example, computer tapes, retain magnetic data.

It could no longer be seen as storage after a disk is degaussed.

Therefore, the final answer is "Using the DoD 5220.22-M method and  Degauss media with a magnet".

Learn more about hard disc at:

brainly.com/question/13329582

#SPJ1

3 0
2 years ago
How do you return a value from a function?
rjkz [21]

Answer:

return instruction used to return a value from a function.

Explanation:

Function is a block of statement which perform the special task.

Syntax for define a function:

type name(parameter_1, parameter_2,...)

{

  statement;

return variable;

}

In the syntax, type define the return type of the function. It can be int, float, double and also array as well. Function can return the array as well.

return is the instruction which is used to return the value or can use as a termination of function.

For return the value, we can use variable name which store the value or use direct value.

4 0
3 years ago
Create a view named MAJOR CUSTOMER. It consists of the customer number, name, bal. ance, credit limit, and rep number for every
Step2247 [10]

Answer:

Following are the solution to the given point:

Explanation:

The solution to this question is defined in the attached in the attached file.

5 0
3 years ago
: For each of the following words identify the bytethat is stored at lower memory address and the byte that is storedat higher m
Aloiza [94]

Answer:

In a <u>little endian computer</u> -The data's least substantial byte is put at the lower address byte. The remaining information will be put in memory in order in the next three bytes.

a)1234

4 is placed at the least significant bits,so this byte stored at lower memory address.

1 is placed at the most significant bits,so this byte stored at higher memory address.

b) ABFC

C is placed at the least significant bits,so this byte stored at lower memory address.

A is placed at the most significant bits,so this byte stored at higher memory address.

c) B100

0 is placed at the least significant bits,so this byte stored at lower memory address.

B is placed at the most significant bits,so this byte stored at higher memory address.

d) B800

0 is placed at the least significant bits,so this byte stored at lower memory address.

B is placed at the most significant bits,so this byte stored at higher memory address.

5 0
3 years ago
Other questions:
  • Write the include directive that allows use of the function headers in the file myFuncs.h.
    13·1 answer
  • A ____ appears at the bottom of your e-mail messages and contains standard information about yourself that the recipient can use
    5·1 answer
  • How to get out of compatibility mode in word?
    15·1 answer
  • What is a project?
    5·2 answers
  • Describe at least two other companies that are direct or indirect competitors to your company. Explain how you will differentiat
    15·1 answer
  • Plz help, correct answer will get brainliest (if i can, if i can't ill still rate and give thanks)
    14·1 answer
  • Which font is most suitable for an academic article on a website? Which is most suitable for casual information?
    5·2 answers
  • in a stop-and-wait arq system, the bandwidth of the line is 1 mbps, and 1 bit takes 10 ms to make a round trip. if the system da
    12·1 answer
  • 10. List three adaptations of wind-pollinated plants to promote pollination.<br>​
    12·1 answer
  • PLEASE HELP WILL GIVE BRAINLIEST!!!’
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!