Professional Documents
Culture Documents
Bitstream 1668162
Bitstream 1668162
Bitstream 1668162
00 Tutorial 2
Control Structures and Classes
Outline
? Take Attendance
? Uploading Problem Sets
? Control Structures
? Simple Classes
1
Uploading?
? When using SecureFX, set the protocol to
?FTP over SSH2? and not just regular
?FTP?, otherwise you will be getting
warning emails about insecure connection.
? Only upload .java files and not the entire
folder or any .class files or any .java~ files.
Control Structures
? List the control structures you have learn in
lecture.
2
if (a<10)
b = 10;
else
b = 0;
else
b = -1;
A slight change
b = 7;
if (a>5) {
if (a<10)
b = 10;
else
b = 0;
if (a>5)
if (a<10)
b = 10;
else
b = 0;
Answer
? Unless braces are used to explicity denote
which if clause is associated with an else
clause, the else clause is associated with the
nearest if clause that precedes it.
Readability of Code
? if (a>5) ? b = 7;
if (a<10) if (a>5) {
b = 10; if (a<10)
else b = 10;
b = 0; }
else else
b = -1; b = 0;
Loops
? How would you write a for loop that calculate the
sum of even numbers from 2 to 20?
? Can you use a while loop to do the calculation
instead?
? The three different kinds of loops are
interchangeable, but sometimes one is better than
the other. Do you know the differences?
Logical Operators
? Do you know what the follow operators mean?
? ==, &&, ||, !=
System.out.println(?x is 0!?);
else
x);
Classes
? What do classes contain?
? Data (what kind of data can they have?)
? Methods
? Lets write a Rectangle class.
? What data fields do you think it should have?
? What methods might it have?
7