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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
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.
 
 
12:31 PM Fri Aug 19
=zyBooks
Check
My library > CS 226T: Java Programming home >
2.1: If-else
Try again
1 error
if (numDifference
learn.zybooks.com
X If numDifference is less than -15, the expression evaluates to true and totalDifference is assigned with -25. If numDifference is
greater than or equal to -15, the expression evaluates to false and totalDifference is assigned with numDifference.
Compilation error:
NumberDifference.java:11: error: incompatible types: int cannot be converted to boolean
= -15) {
^
EzyBooks catalog ? Help/FAQ Stacey Queen
Construct 2.1.2: Multi-branch if-else statement. Only 1 branch will execute.
}
else if (expression2) {
2
if (expression1) {
// Statements that execute when expression1 is true
// (first branch)
Multi-branch if-else statements
An If-else statement can be extended to have three (or more) branches. Each branch's expression is checked in sequence. As soon as one
branch's expression is found to be true, that branch's statement execute (and no subsequent branch is considered). If no expression is true,
the else branch executes.
VPN 97%
// Statements that execute when expression1 is false and expression2 is true
// (second branch)
}
Feedback?
Transcribed Image Text:12:31 PM Fri Aug 19 =zyBooks Check My library > CS 226T: Java Programming home > 2.1: If-else Try again 1 error if (numDifference learn.zybooks.com X If numDifference is less than -15, the expression evaluates to true and totalDifference is assigned with -25. If numDifference is greater than or equal to -15, the expression evaluates to false and totalDifference is assigned with numDifference. Compilation error: NumberDifference.java:11: error: incompatible types: int cannot be converted to boolean = -15) { ^ EzyBooks catalog ? Help/FAQ Stacey Queen Construct 2.1.2: Multi-branch if-else statement. Only 1 branch will execute. } else if (expression2) { 2 if (expression1) { // Statements that execute when expression1 is true // (first branch) Multi-branch if-else statements An If-else statement can be extended to have three (or more) branches. Each branch's expression is checked in sequence. As soon as one branch's expression is found to be true, that branch's statement execute (and no subsequent branch is considered). If no expression is true, the else branch executes. VPN 97% // Statements that execute when expression1 is false and expression2 is true // (second branch) } Feedback?
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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education