Tonight's lecture began with a discussion of the Boolean data type. Booleans have values of true and false.
Here are the Boolean operators and some descriptions of their uses:
AND - designated by & &
< boolean >
& &
< boolean > - >
< boolean >
Returns true if both inputs are true. Returns false if not.
Some java examples of & &:
boolean x = true;
boolean y = false;
boolean z =
x
& &
y;
This would return ``false'' because of y. However, if we had:
boolean w = x & & x;
w would return ``true'' because x represents true inputs in each case of x.
Here's another java example:
int a = IO.read_int ();
int b = IO.read_int ();
int c = IO.read_int ();
boolean x = (a
<
c)
& &
(a
<
b)
Assume that the input stream is:
7, 4, 10..
What will be the value of x? FALSE
OR - designated by | |
< boolean >
| |
< boolean > - >
< boolean >
Returns true if at least one input is true. Returns false otherwise.
NOT - designated by
!
! < boolean > - >
< boolean >
Returns the ``other'' boolean.
|
CG then began a discussion on iteration and its three main mechanisms - ``while'', ``for'', and recursion. Other terms and ideas defined tonight included: the while statement, counter control loop, data control loop, and incremental programming. See the glossary for these definitions.
CG wrote a simple program to illustrate the use of incremental programming. I won't replicate it here, but here are the major ideas:
Problem: Read three integers and display the difference between the largest and the smallest values.
The sequence of programs will be...
P0: Read and echo three integers.
P1: Same as P0, plus determine and display the maximum value.
P2: Same as P1, plus determine and display the lowest value.
P3: Same as P2, plus compute and display the difference.
P4: Same as P3, but delete all ``extra'' output.
As you can see, each step between P0 to P4 brings us ``incrementally'' closer to the final product.