[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
[CS152 2005S]
[CS152 2005F]
Back to Binary Representation of Integers. On to Static Methods.
Held: Wednesday, February 8, 2006
Summary: Today we investigate conditional operations in Java.
Overview:
Assignments
Notes:
Overview:
if
statement.if
or conditional statement is one of the
simplest control structures.
if
statement.
if (test) { statements; } // if
boolean
(truth) value.
For fluffier pancakes, decrease the milk by 10%.
If above 5000 ft, decrease the oven temperature by 25 degrees F.
if (test) { statements; } // if text else { statements; } // if not test
if
is slightly different from Scheme's.
if
selects between expressions and returns a value.
if
selects between statements and does not return
a value.
if
statements, such as Scheme's cond
.
Instead, use the following:
if (test1) { stuff1 } else if (test2) { stuff2 } else if (test3) { stuff3 } else if (testn) { stuffn } else { default-stuff }
boolean
values.
boolean
is a primitive type, like int
or double
.
#t
and #f
.
true
or false
. They
boolean
values with
Boolean expressions.
x
and
y
, with one of the following.
x < y
(less than)
x <= y
(less than or equal to)
x == y
(equal to; note there are two
equals signs)
x != y
(not equal to)
x >= y
(greater than or equal to)
x > y
(greater than)
comes between) rather than prefix (
comes before) operations.
b1 && b2
(and)
b1 || b2
(or)
!b
(not)
if ((i >= 1) && (i <=10)) { ... }
equals
method. (It does need to be defined for most classes.)
if (operator.equals("*")) { pen.println(x*y); }
compareTo
method.
obj.compareTo(other)
compareTo
returns
obj
naturally precedes
other
obj
is naturally equal to
other
obj
naturally follows
other
compareTo
is transitive and reflexive.
BigDecimal
, d, is
between 0 and 1 (inclusive), we might write
if ((d.compareTo(BigDecimal.ZERO) >= 0) && (d.compareTo(BigDecimal.ONE) <= 0) { ... }
Back to Binary Representation of Integers. On to Static Methods.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
[CS152 2005S]
[CS152 2005F]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue May 9 08:31:30 2006.
The source to the document was last modified on Thu Jan 12 14:58:06 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2006S/Outlines/outline.11.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby