2.1.3: Basic if-else. 422784.2543518.qx3zqy7 Jump to level 1 Write an if-else statement for the following: If numDifference is less than -15, execute totalDifference = -25. Else, execute totalDifference = numDifference.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.

![12:31 PM Fri Aug 19
=zyBooks
CHALLENGE
ACTIVITY
422784.2543518.qx3zqy7
Jump to level 1
Write an if-else statement for the following:
My library > CS 226T: Java Programming home >
2.1: If-else
6789
2.1.3: Basic if-else.
3 public class NumberDifference {
4
5
10
11
12
13
14
15
16
17
18
19
20
21 }
If numDifference is less than -15, execute totalDifference = -25. Else, execute totalDifference = numDifference.
1 import java.util.Scanner;
2
-------
Check
}
public static void main (String [] args) {
int totalDifference;
int numDifference;
if (numDifference = -15) {
totalDifference
-25;
}
Scanner scnr = new Scanner(System.in);
numDifference = scnr.nextInt (); // Program will be tested with values: -14, -15, -16, -17.
else {
}
learn.zybooks.com
=
totalDifference =
Try again
System.out.println(totalDifference);
numDifference;
EzyBooks catalog ? Help/FAQ Stacey Queen
2
VPN 97%
X If numDifference is less than -15, the expression evaluates to true and totalDifference is assigned with -25. If numDifference is
ID:SS
Diff
1
2](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F788fc729-a951-45c4-9909-47eea7bbf82f%2F1de4d576-bf11-4e34-80c9-e47ebefcd049%2F9p4eb9m_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images









