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]
3 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]3 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
Indicate the order that the three files will be processed <br><br> Please answer
defon
The answer is 10 because I looked it up
6 0
4 years ago
James added a new video card and needs to get a power supply that will have enough power to run the new card. When researching t
Shtirlitz [24]

Answer:

the voltage it will need to give and take

Explanation:

it all depends on the amount of voltage the video card requires say the video card requires 150v you would have to buy a power supply that would be able to support that and all the other parts so you would buy a 550v power supply

3 0
3 years ago
True / False
blagie [28]

Answer: True

Explanation:

Variable length instructions generally implemented by CISC processors use memory more efficiently than fixed length instruction of RISC processors sets because CISC supports array whereas RISC does not. Also CISC uses more complex addressing modes which consumes less memory cycles and the the program is also reduces. In Fixed length instruction in RISC processor the simple instructions has to be used a number of time which leads to more memory cycles.

7 0
4 years ago
_______ and _____ are two major techniques involved in green computing. NextReset
FrozenT [24]
Green computing is the use of computers and related resources which is environmentally responsible. Energy-efficiency and e-waste are two major techniques involved in green computing. Energy efficiency involves implementation of energy-efficient central processing units (CPUs), servers and peripherals as well as reduced resource consumption. And e-waste is the proper disposal of electronic waste.


3 0
3 years ago
Read 2 more answers
Refer to the color wheel to identify the color scheme:
nekit [7.7K]

I believe it's Monochromatic?

I'm not sure but I think it's that.

Good luck! :D

5 0
3 years ago
Other questions:
  • A ____ is a structure that allows repeated execution of a block of statements.
    13·2 answers
  • Which of the following statements is true according to the code?
    12·1 answer
  • Software designed specifically for managing real estate is an example of ________ software. Select one: A. e-commerce B. vertica
    7·1 answer
  • When the hyper-v role is added to a windows server 2012 r2 server, what is loaded first during boot?
    6·1 answer
  • By default, the Windows desktop displays
    6·1 answer
  • Three of the most important jobs of security management are to ensure _____ are organized according to sensitivity, ensure that
    10·1 answer
  • PLEASE HELP! 2D Animation!
    12·1 answer
  • Which command should you use if you want your workbook with a different file name?
    15·1 answer
  • Question 3 10 points Save Answer Many companies in the computer industry introduce new products and services frequently in an at
    7·1 answer
  • Why is it important to prepare the farm resources before you start working? explain​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!