In JAVA, answer the following:Given an int variable n that has already been declared, write some code that repeatedly reads a value into n until at last a number between 1 and 10 (inclusive) has been entered.

ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.

Answers

Answer 1
Answer:

Answer:

The JAVA program is as follows.

import java.util.Scanner;

public class Program

{

   static int n;

public static void main(String[] args) {

    //scanner object

    Scanner stdin = new Scanner(System.in);

    //loop executes till number entered is in the range of 1 to 10

    do

    {

        System.out.print("Enter any number: ");

        n = stdin.nextInt();

    }while(n<1 || n>10);

    System.out.println("Number is valid. Exiting...");

}

}

OUTPUT

Enter any number: 0

Enter any number: 23

Enter any number: 10

Number is valid. Exiting...

Explanation:

The program is explained.

1. The integer variable, n, is declared static since the variable should be accessible inside main() which is static.

2. An object of Scanner, stdin, is created inside main().

3. Inside do-while loop, the user is asked input any value for n.

4. The loop continues till user inputs a number which is not in the given range, beginning from 1 to 10.

5. The loop will not be terminated till the user enters a valid input.

6. Once a valid input is entered, the message is displayed to the console and the program ends.

7. The variable, n, is declared at the class level and is a class variable. Class variables are declared inside the class but outside all the methods in that class.

8. Since JAVA is a purely object-oriented language, all the code is written inside class.

9. The object of class is not created since only one class is included in the program. If more than one class is included, then the object of the class which does not has the main() method will be created inside main().

10. User input for integer is taken via scanner object and using nextInt() method.

11. The methods, print() and println() display the messages to the console. The only difference is that println() inserts a new line after displaying the message.

12. The name of the class having main() and the name of the program should be the same.


Related Questions

A benefit of flashcards is that they area. Portable c. Very large b. Contains lots of information d. Ask many questions on one card
Computer privacy typically occurs when which of the following is violated?a. intellectual property b. open source software c. blog post d. computer hardware
How do you add binary numbers?
How can i take a virus off a computer without taking it to be fixed ??
I'm having trouble using my NetMeeting software. In order to use the software, it tells me I need to enter my IP address, but I don't know what it is. Can you tell me where to find it? a) Check your computer's network settings b) Contact your internet service provider (ISP) c) Look on the NetMeeting software interface d) Restart your computer

If the Spelling and Grammar checker suspects you have a misspelled word, it will _____.a. offer suggestions for the correct spelling
b. pull up the Dictionary for you to search for the correct spelling
c. supply you with Internet search results on the word
d. automatically replace the word with the one it believes is correct

Answers

a offer suggestions for the correct spelling

A machine that is used to print newspapers is a _____. natural resource human capital capital good renewable resource

Answers

The answer is Capital good

Machines that are used to print newspapers are examples of capital goods. Capital goods, by explanation, are durable items that businesses use to produce goods and services as an input to produce goods for other businesses. They include machinery, equipment, and tools. Those who understand accounting treat capital goods as fixed assets and are known as “plant, property and equipment”.

The answer to the question stated above is capital good/s.

Capital goods are any tangible assets which an organization is using to produce goods or services. Capital goods include office buildings, equipment and machinery.
Thus, a
 machine that is used to print newspapers is a capital good.

What are three common ways individuals enter the internal audit profession?

Answers

Answer:

Three common ways individuals enter the internal audit profession are through education, such as obtaining a degree in accounting or auditing, gaining experience through internships or entry-level positions in auditing, or transitioning from related roles such as accounting or finance.

Which is not a test Oracle Option 1: The existing system (For a benchmark) Option 2: The code Option 3: Individual’s knowledge Option 4: User manual

Answers

Explanation:

find out what reasons influenced the location of the settlement you are researching

Final answer:

Option 4: User manual

Explanation:

In software testing, a Test Oracle provides the expected outcome for a test case. Option 4: User manual is not a Test Oracle because it may not provide consistent or accurate expected outcomes for testing.

The Test Oracle is a concept in software testing that helps in determining whether a test has passed or failed. It provides the expected outcome of a test case. Given the options provided; the existing system (for benchmarking), the code, individual's knowledge, and user manual, Option 4: User manual is not a Test Oracle. While an individual's knowledge is valuable, it does not in itself serve as a benchmark for testing. Unlike the existing system, the code, or user manual, it may not provide consistent or accurate expected outcomes for testing due to inherent human variable factors.

Learn more about Test Oracle here:

brainly.com/question/36601250

#SPJ11

1. How many lines of symmetry does the isosceles trapezoid have? (1 point)​

Answers

Isosceles trapezoid would be a trapezoid with equal base angles and hence equal length on the lateral sides, and further discussion can be defined as follows:

  • In the given figure's line of symmetry seems to be the imaginary service that runs thru the center of the figure and divides it into mirror-image halves perfectly fit.
  • The isosceles trapezoid contains two simultaneous opposing sides & two non-parallel congruent edges.
  • These have one line segment that runs through the center of the picture and divides the image into rearview halves together specific and defined.

Therefore, the answer is "one line of symmetry".

 Learn more:

brainly.com/question/12854321

It has one line of symmetry

Is this a bad CPU chip I need help asapppppp

Answers

Answer:

Potentially bad.

Explanation:

It appears that on the CPU, there are bent pins.  From the picture perspective, these are on the far right of the CPU and near the bottom left.  Bent CPU pins can potentially be repositioned, but more than likely will break.  When pins break, the CPU will no longer work as intended as the chipset will not be able to make the assumed calls to those pins on the CPU.  If this is a new chip, and you didn't cause this damage, you should RMA the CPU back to the vendor you bought it from.

Cheers.