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
To change the backround color of a page, which tab would you use?
ivann1987 [24]
I have concluded the answer is a
4 0
3 years ago
Read 2 more answers
Which of these consoles have 64 bit architecture
tigry1 [53]

I don't know if this is on your list, but I know for a fact that the Nintendo 64 system (or N64) has a 64-bit architecture.

8 0
3 years ago
5. Write a function that takes two lists of integers and returns a list containing tuples with corresponding elements from both
Allisa [31]

Answer:

def corresponding_of_lists(lst1, lst2):

   c = ""

   corresponding_list = []

   if (lst1 is None) or (lst2 is None):

       return None

   else:

       for i in lst1:

           for j in lst2:

               c = "(" + str(i) + "," + str(j) + ")"

               corresponding_list.append(c)

   return corresponding_list

Explanation:

- Create a function called corresponding_of_lists that takes two lists as parameter

- Initialize an empty list to hold the corresponding values

- Check if any of the lists are null, if they are return None

- Otherwise, get the corresponding elements and put them into the corresponding_list

Return the corresponding_list

7 0
3 years ago
Each time an end user clicks a hyperlink, the browser generates a(n) _____ page request that is sent to the designated web serve
igomit [66]

Answer: HTTP GET

Explanation: There are many  HTTP(Hypertext Transfer protocol) requests sent to the server from the client .The page that gets request while the hyperlink page is clicked by the client, opens a HTTP GET page that belongs to the Internet protocol's(IP)suite by server. It is a process for the revival of the data from a particular server. The data does not get effected during the process of the retrieval.

3 0
3 years ago
Create and test an HTML document that describes nested ordered lists of cars. The outer list must have three entries: compact, m
melomori [17]

Answer:

Check the explanation

Explanation:

All website around the world/internet is a collection of different web pages, HTML can be referred to as the single most essential standard when it comes to web design, as well as it being the only one that’s enormously required or needed if you plan to create a web page.

to answer the question above, we will be creating an HTML document that describes nested ordered lists of cars, kindly check the attached images below to see the written codes to solve the question.

8 0
3 years ago
Other questions:
  • HELLLLLP ill make you brainiest and ill give u a lot of points if you HELP ME Directions Part One.
    12·2 answers
  • In general, what is the leftmost point of a circle with radius r centered at (x,y)?
    8·1 answer
  • Type the correct answer in the box spell all words correctly
    8·1 answer
  • What is an example of a transition effectl
    7·1 answer
  • Technologies are having a negative impact on businesses.
    8·1 answer
  • EX 3.8 Write code to declare and instantiate an object of the Random class (call the object reference variable rand). Then write
    6·1 answer
  • Choose all the items that represent potential ways to find a job opening.
    14·1 answer
  • All health information available on the internet is valid. <br> a. true <br> b. false
    6·1 answer
  • Drag each tile to the correct box.
    15·1 answer
  • How to clear a function in functional component react.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!