if (amount <= balance)
balance = balance - amount;
if (amount <= balance)
balance = balance - amount;
else
balance = balance - OVERDRAFT_PENALTY;
Example:
Purpose:To execute a statement when a condition is true or false |
Example:
Purpose:To group several statements together to form a single statement |
if (amount <= balance)and how do you fix it?
newBalance = balance - amount; balance = newBalance;
Java |
Math Notation |
Description |
> |
> |
Greater than |
>= |
≥ |
Greater than or equal |
< |
< |
Less than |
<= |
≤ |
Less than or equal |
== |
= |
Equal |
!= |
≠ |
Not equal |
a = 5; // Assign 5 to a
if (a == 5) . . . // Test whether a equals 5
double r = Math.sqrt(2);
double d = r * r -2;
if (d == 0)
System.out.println("sqrt(2)squared minus 2 is 0");
else
System.out.println("sqrt(2)squared minus 2 is not 0 but " + d);
final double EPSILON = 1E-14;
if (Math.abs(x - y) <= EPSILON)
// x is approximately equal to y
String middleInitial = null; // Not set
if ( . . . )
middleInitial = middleName.substring(0, 1);
if (middleInitial == null)
System.out.println(firstName + " " + lastName);
else
System.out.println(firstName + " " + middleInitial + ". " + lastName);
String a = "1";
String b = "one";
double x = 1;
double y = 3 * (1.0 / 3);
Enter a magnitude on the Richter scale: 7.1 Many buildings destroyed
if (condition1)
{
if (condition1a)
statement1a;
else
statement1b;
}
else
statement2;
If your filing
status is Single |
If your filing
status is Married |
||
Tax Bracket |
Percentage |
Tax Bracket |
Percentage |
$0 . . . $21,450 |
15% |
0 . . . $35,800 |
15% |
Amount over $21,450, up to
$51,900 |
28% |
Amount over $35,800, up to
$86,500 |
28% |
Amount over $51,900 | 31% |
Amount over $86,500 | 31% |
Please enter your income: 50000 Please enter S (single) or M (married): S The tax is 11211.5
if (richter < 3.5)
r = "Generally not felt by people";
else if (richter < 4.5)
r = "Felt by many people, no destruction";
else if (richter < 6.0)
r = "Damage to poorly constructed buildings";
. . .
A |
B |
A && B |
true |
true |
true |
true |
false |
false |
false |
Any |
false |
A |
B |
A || B |
true |
Any |
true |
false |
true |
true |
false |
false |
false |
A |
! A |
true |
false |
false |
true |