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
hoa [83]
2 years ago
12

Can anyone help me figure out why my if statements are not executing properly? When the program executes with 7 as the value for

num it should be executing the first line, but instead it goes to the third and displays, " a single digit."
public static String numberInfo(int num){
//TODO student
String numInfo;

if (num == 7) {
numInfo = "lucky sevens!";
}
if (num == 42) {
numInfo = "the answer to life the universe and everything.";
}
if (num < 10) {
numInfo = "a single digit.";
}
else {
numInfo = "a positive number.";
}
return numInfo;
}
Computers and Technology
1 answer:
mariarad [96]2 years ago
5 0

Answer:

For the value of 7 of num, there are actually two if statements that are true and their contained code is executed.

So your line numInfo = "lucky sevens!"; is executed for sure, but then numInfo gets overwritten with by numInfo = "a single digit.";

To fix it, you have to decide how you want the program to behave, since technically, both numInfo's are equally correct.

- if you want to execute at most one if condition, chain them together like if (...) { ... } else if(...) { ... } etc.

- if you want to return multiple numInfo's, turn it into a collection where you add strings

You might be interested in
Distinguish among packet filtering firewalls, stateful inspection firewalls, and proxy firewalls. A thorough answer will require
4vir4ik [10]

Answer:

packet filtering

Explanation:

We can use a packet filtering firewall, for something like this, reasons because when visiting a site these types of firewalls should block all incoming traffic and analyze each packet, before sending it to the user. So if the packet is coming from a malicious origin, we can then drop that packet and be on our day ;D

7 0
3 years ago
Which statement will read an entire line of input into the following string object?
Solnce55 [7]

Answer:

getline(cin, address);

Explanation:

Given

String object: address

Required

Statement that reads the entire line

The list of given options shows that the programming language is c++.

Analysing each option (a) to (e):

a. cin<<address;

The above instruction will read the string object until the first blank space.

Take for instance:

The user supplied "Lagos state" as input, only "Lagos" will be saved in address using this option.

b. cin address:

This is an incorrect syntax

c. getline(cin,address);

Using the same instance as (a) above, this reads the complete line and "Lagos state" will be saved in variable address

d. cin.get(address);

address is created as a string object and the above instruction will only work for character pointers (i.e. char*)

<em>From the above analysis, option (c) is correct.</em>

6 0
2 years ago
__________ states that network connection speeds for high-end users will increase by 50 percent per year, enabling new companies
Liula [17]

Answer:

Nielsens law

Explanation:

4 0
1 year ago
Is October tornado season?
Reptile [31]
No October is not tornado season
5 0
3 years ago
Read 2 more answers
Andrew has invested in a new CAD system to use in his workshop. What changes have occurred because he adopted the new system?
Bad White [126]

Answer:

B.   CAD produces designs that are of the highest quality.

C.   CAD provides systems for error-free manufacturing.

Explanation:

B.   CAD produces designs that are of the highest quality.

CAD does produce the highest quality of design, way better than what traditional paper plans can do.

C.   CAD provides systems for error-free manufacturing.

Many manufacturing systems can read CAD designs directly before the need of a human intervention in between, that eliminates possible errors.

Answers A and D are not true, because once passed the learning-curve, CAD greatly accelerates the production of designs.  And we know the learning-curve is behind them because the question says he has adopted the new system.

5 0
3 years ago
Read 2 more answers
Other questions:
  • _____ provide the standards, syntax, statements, and instructions for writing computer software
    14·1 answer
  • You are holding a rock tied to a string, which is an example of a pendulum. identify and explain the proper term for each part o
    10·2 answers
  • Alison wants to add her company name at the bottom of every page in her document. Which option should she use?
    11·2 answers
  • Force field meaning in science fiction
    6·1 answer
  • Which of the following should get a Page Quality (PQ) rating of Low or Lowest?
    5·1 answer
  • Question 1. (50 points) 1.Write a program that computes information related to a sequence of entries regarding age of customers.
    6·1 answer
  • What does “human-like” mean when we are talking about a machine?
    7·1 answer
  • How did the use of ARPANET change computing?
    14·1 answer
  • 4. Compute the following additions
    7·1 answer
  • Energy/power management systems, kitchen appliances, smart televisions, baby monitors, fitness trackers, and personal health mon
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!