Lecture Notes, class 4 for csc211.

Prepared by: Anthony Larrain

These notes serve as an outline to the lecture, they are not intended to be complete. You should be reading the assigned sections. During class I may include or omit certain topics.


The Scanner Class

See PoundsToKilograms.java and SimpleTax.java


Using JOptionPane for Output


Control Flow

Unless directed otherwise the statements of a method are executed sequentially, one after the other, starting with the first. This is called sequential execution . There are a few ways in Java to alter the program flow so that the next statement executed, may be other than the next one in sequence. This is called transfer of control

3 ways to alter the flow of control


The if Statement

The if statement has the form.

  if ( condition is true )
     execute this-statement;
 

The condition enclosed in parentheses must be an expression that evaluates to true or false. Such an expression is called a boolean expression.


The if-else Statement

 if( condition )
   statementA;
 else
   statementB;
 

If the condition is true we execute statementA, if condition is false execute statementB.


Comparison Operators

The comparison operators:

See COperators.java


More Operators

UML


More Features