Lecture 6 Objectives [Nov 02]prev
next
OPENING LINE:
In the shade of the house, in the sunshine of the river bank by the boats, in
the shade of the sallow wood and the fig tree, Siddhartha, the handsome
Brahmin's son grew up with his friend Govinda.
[Siddhartha,
Herman Hesse]
At the end of today's class you should
HAVE READ:
KNOW:
- The concept of a for loop
- How a for loop can be mapped to a while
loop.
- The concept of variables initialized for use only within
the for loop
- The elements of a for loop
- The control flow within a for loop
- How to use Scanner to take input from a File on disk
rather than from the keyboard.
BE ABLE TO:
- Write a program that prints to the console the numbers
from 1 to 20
- Write a program that prints to the console the numbers
from 20 to 1
- Write a program that prints to the console the numbers 1,
3, 5, 7, 9, ..., 15, 17, 19
- Write a program to retrieve the first line of a File
(terminated by the '\n' character) on disk and print it to the console.
DAILY QUESTION:
- What is the output of the following loop? Identify
the connection between the value of n and the value of the variable log.
int n = 1024;
int log = 0;
for (int i = 1; i < n; i = i * 2) {
log++;
}
System.out.println (n + " " + log); |
Sample Exam Question:
LoadFromFile
Write a program that loads two integers from a file "TEST.txt"
and prints them to the screen. Note that this example uses Exceptions (a
concept we haven't yet discussed in class)