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
Give an example of a language L such that |L|=5 and |L^2|=16.
Basile [38]

Answer:

He can define pas follows: Let P be defined on the set of languages accepted by some Turing machine M. Let it be True if 10 ] is 5 and False otherwise.  

Explanation:

The domain of P is the SD languages since it is those languages that are accepted by some Turing machine H. P is nontrivial since P({ a, aa, aaa, aaaa, aaaaa, aaaaaa, b, bb, bbb, bbbb, bbbbb, bbbbbb } ) is True and P ( 5 ) is False.  

Thus {< M> is a Turing machine and I L I - 5 and  I L I - 16 }

7 0
2 years ago
Choose the best answer from the options below to complete the following sentence.
Lemur [1.5K]

Answer:

its A. the answer to your question is preserved. :)

7 0
2 years ago
Successful Web sites such as StumbleUpon ( www.stumbleupon) and Digg ( www.digg) use ____ by inviting their visitors to vote on
aliina [53]

Answer:

"Crowdsourcing" is the correct answer for the above question.

Explanation:

  • Crowdsourcing is a term from which any organization advertises the thinks or can get the ideas or solutions for any particular problem.
  • It is a term that refers to the problem to the number of solvers to achieve the result correct and frequent.
  • For example, If anyone wants to prepare the two websites. Then he assigns the works to the number of people and the works done faster with the help of this.
  • The above question states that some websites can be successful with the help of the type of work. They are successful with the help of crowdsourced work. Because it saves time. So the answer is Crowdsourcing.
3 0
3 years ago
A network system administrator would typically be responsible for which of the following duties?
EleoNora [17]

Answer:

A) Maintaining the shared connections between offices

Explanation:

Plz mark brainliest

3 0
3 years ago
Read 2 more answers
Which service uses a broadband connection?
Sidana [21]

Answer:

d

Explanation:

because all in one question form

5 0
3 years ago
Other questions:
  • What are the example of dedicated computers?
    5·1 answer
  • Who is typically considered to be the father of computing
    6·1 answer
  • Can y’all help me with these questions ?
    5·1 answer
  • Recall that through either photographic or computer technology, researchers can make a composite (or "averaged") face out of any
    11·1 answer
  • How do i show all emails from same sender in outlook
    13·2 answers
  • Which of the following explains the growing need for a standard IT professional licensing program? Check all of the boxes that a
    11·1 answer
  • Why do agriculture and natural resource systems vary from state to state?
    8·1 answer
  • I'm having trouble changing my google account password
    12·1 answer
  • HI How are you anyways are any of you intreseted in my giveaway
    7·2 answers
  • Click here for a answer
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!