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
• R7.9 Write enhanced for loops for the following tasks.
alexdok [17]

Answer:

a is the correct answer

Explanation:

correct me if I'm wrong hope it's help thanks

3 0
3 years ago
An administrator has initiated the process of deploying changes from a sandbox to the production environment using the Force IDE
Pani-rosa [81]

Option A because the environment should be selected for which the changes are to be applied. In a time Force IDE has many project environments for example maybe a java project and C++ project would be there on sandbox, so the environment selection is important.

Option B because the related changed sets should be specified so that other developers that have access to the project can see the changes being made.

Option D The data fields that are needed to be deployed should also be provided so that the updated version can be seen by other developers.

Rejected Options :

Option C user name and password has nothing to do with the production environment because if the user has it only then it can come and make changes.

6 0
3 years ago
If someone wouldn’t mind answering the first question for me
kompoz [17]

1.

  • Keep the title bold
  • <u>Underline</u> important statements
  • Colour the words (but the document shouldn't be too colourful)
8 0
3 years ago
Question 12
AlladinOne [14]

Which is a multicast address ?

ans: 241.2.2.1

6 0
2 years ago
List the steps to look it install and then run a program or mobile app
Luda [366]

Answer:

1. Open a cloud installer (the source), which is usually Play Store, Aptoide, or UpToDown, in the case of Android phones.

2. Request the package from the server, which will be transmitted via an internet connection. Usually called "downloading".

3. Allow the package provider (mobile store) to install the app on the system, this being the "install" part, where it's put together.

4. Run the app by, usually, pressing the icon in the app drawer.

3 0
3 years ago
Other questions:
  • A ____ client locates all or most of the processing logic on the server.
    11·1 answer
  • Write a method reverse( ) for OurLinkedList class. The method should return a new OurLinkedList object that is the reverse of th
    8·1 answer
  • If there are 8 opcodes and 10 registers, a. What is the minimum number of bits required to represent the OPCODE? b. What is the
    10·1 answer
  • What is an accurate definition of a goal?
    15·2 answers
  • When targeting customers of the consumer population at market a product, what type of segmentation information would be most hel
    12·2 answers
  • Which of the following is NOT a valid name for a function?
    5·1 answer
  • In batch operating system three job J1 J2 and J3 are submitted for execution each job involes an I/O activity a CPU time and ano
    13·1 answer
  • What are the three main components of a for loop?
    9·1 answer
  • In a word-processing program, what are the easily accessible icons that allow you to print, save and change fonts with a click o
    8·1 answer
  • Programs for embedded devices are often written in assembly language. Some embedded processors have limited instructions, like M
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!