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
ankoles [38]
3 years ago
6

In the Happy Valley School System, children are classified by age as follows:less than 2, ineligible2, toddler3-5, early childho

od6-7, young reader8-10, elementary11 and 12, middle13, impossible14-16, high school17-18, scholargreater than 18, ineligibleGiven an int variable age, write a switch statement that prints out, on a line by itself, the appropriate label from the above list based on age.
Computers and Technology
1 answer:
Greeley [361]3 years ago
7 0

Answer:

int age = 10;

switch (age){

case 0:

case 1:

System.out.println("ineligible");

break;

case 2:

System.out.println("toddler");

break;

case 3:

case 4:

case 5:

System.out.println("early childhood");

break;

case 6:

case 7:

System.out.println("young reader");

break;

case 8:

case 9:

case 10:

System.out.println("elementary");

break;

case 11:

case 12:

System.out.println("middle");

break;

case 13:

System.out.println("impossible");

break;

case 14:

case 15:

case 16:

System.out.println("high school");

break;

case 17:

case 18:

System.out.println("scholar");

break;

default:

System.out.println("ineligible");

}

Explanation:

In java and many other programming languages, a switch statement is a way of having multiple branching options in a program. This is usually considered a more efficient way than using multiple if....else if statements. and the expression variables could be byte, char int primitive data types. etc. every branch (option) in a switch statement is followed by the break statement to prevent the code from "falling through". In the question The variable age is declared as an int and initialized to 10. and tested against the conditions given in the question.

You might be interested in
What is the purpose of a email
jasenka [17]

Answer:

An email is a digital message sent electronically from one computer to one or more other computers. Emails are flexible and can be used for giving instructions, serving as documentation, providing confirmation, communicating rules and procedures, making recommendations, providing a status update, making an inquiry.

7 0
3 years ago
Read 2 more answers
Which statement compares the copy and cut commands?
ella [17]

Answer: duplicate

Explanation:

5 0
2 years ago
Read 2 more answers
In a TCP session hijacking attack, if the server is waiting for data starting from sequence number X, but we used X 100 in our a
Irina18 [472]

Answer:

In the presence of packets transfer between client and server in a TCP session, the attack will be successful if the number of the sequence is approximately X+100. Otherwise, the attack will not be successful (i.e. fail).

Explanation:

Generally, it is important to ensure that there is a successful operation in the operation of a TCP session. In the presence of packets transfer between client and server in a TCP session, the attack will be successful if the number of the sequence is approximately X+100. Otherwise, the attack will not be successful (i.e. fail).

4 0
3 years ago
Read 2 more answers
Which of the following statements contains an error?
ASHA 777 [7]
I. is syntactically correct if genderString exists. if genderString, for example, is "Male", then char gender would be the character at index 0 (the first character), meaning 'M'.

II. is incorrect. It is using the comparison operator (==) instead of the assignment operator (=). It is also setting a boolean variable to a String value of 'F'. Boolean values cannot hold string values, and can only hold true & false. 

III. is correct if ageString only contains numbers (presumably, it does, as it's called ageString). Integer.parseInt is a function that converts String values to integer values if the string values only contain numerical characters.

The answer in this case should be B. II only.
5 0
3 years ago
A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that
Reptile [31]

Answer:

  1. with(open("numbers.txt")) as file:
  2.    data = file.readlines()  
  3.    runsum = 0
  4.    largest = 0
  5.    
  6.    for x in data:
  7.        if(int(x) > largest):
  8.            largest = int(x)
  9.            runsum += largest  
  10.    
  11.    print(runsum)

Explanation:

The solution code is written in Python 3.

Firstly, open a filestream for numbers.txt (Line 1) and then use readlines method to get every row of data from the text files (Line 2).

Create a variable runsum to hold the running sum of number bigger than the maximum value read up to that iteration in a for loop (Line 3).

Use a for loop to traverse through the read data and then check if the current row of integer is bigger than the maximum value up to that point, set the current integer to largest variable and then add the largest to runsum (Line 6 - 9).

At last display the runsum to console terminal (Line 11).

8 0
3 years ago
Other questions:
  • Again, consider what you believe to be the goal of performing a penetration test. Why would you worry about doing any privilege
    14·1 answer
  • Which of the following is a category of social media?
    8·2 answers
  • Which of the following commands would instruct OSPF to advertise ONLY the 192.168.10.0/24 network in Area 0?
    13·1 answer
  • What saw do you use to cut wood in design and technology
    7·1 answer
  • A _________ is a task at the lowest level of the WBS that represents the level of work that the project manager uses to monitor
    5·1 answer
  • A good practice when using public domain content is to
    7·1 answer
  • Demonstrate the register addressing mode for the following instructions. Also what addressing mode belongs to these instructions
    11·1 answer
  • What is functionality criteria or alternative word
    8·1 answer
  • Consider the following code segment.
    12·1 answer
  • You defined a class and saved it as shoe.py.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!