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
The ________ is an area where you can position fields to use for filtering the PivotTable and thereby enabling you to display a
Studentka2010 [4]

Answer: FILTERS area

Explanation: PivotTable is the kind of a tool that is used for the calculation of the data by analyzing ,summarizing ,comparing it according to the pattern and the sequence of the data.In this this tool. filter is used as the component for the filtering of the data in small/minor unit by analyzing it deeply. Different filter techniques is used in analyzing of the spreadsheet in PivotTable.

3 0
2 years ago
In a process called _____, excel continually reviews the workbook for errors in formulas as you create or manipulate it.
Nataliya [291]
Background formula checking is the process in excel that enables it to review continually the whole file for formula errors. This also functions while you are creating and entering new formulas in cells. When an error is found certain codes shows on the cells.
3 0
3 years ago
One way to prepare for filing the PROFILE is to:
kozerog [31]
I think I am not sure that it is probably b
8 0
3 years ago
Read 2 more answers
Define input hardware​
luda_lava [24]
It’s a piece of hardware (you can touch it) that changes something on the screen. Examples are a keyboard putting letters on the screen or a mouse moving the cursor
6 0
2 years ago
3. A vulnerability is: a. A hacker searching for open ports b. A known attack method c. An incorrectly implemented policy d. All
ELEN [110]

Answer:

A

Explanation:

A hacker searching for open ports denotes vulnerability of computer (to hacking).

Cheers

7 0
3 years ago
Other questions:
  • Why is it more important now than ever before to know how to evaluate websites and other online sources of information?
    7·1 answer
  • How long does it take to wire a house?
    14·2 answers
  • A hard drive cannot be partitioned until the device _________ is set.
    15·1 answer
  • A(n) ________ operator, such as the greater than or less than symbol, can be used in a query criterion to limits the results pro
    12·2 answers
  • Biomimicry is the term used when engineers are inspired by objects found in nature? Group of answer choices True False
    10·1 answer
  • Pls help will mark brainliest as soon as u awnser
    15·1 answer
  • What would the internet be like today if there was no World Wide Web?
    9·1 answer
  • Which of these can be a problem for people with accessibility issues? Select 4 options.
    7·1 answer
  • The courts can adjust the penalties in lawsuits to reflect the fact that infringements may be _____.
    5·2 answers
  • Classes that depend on field names from parent classes are said to be ____ because they are prone to errors.Group of answer choi
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!