Java Quick Reference Guide
Java Quick Reference Guide
The while Loop ( pre-test loop ) The for Loop ( pre-test loop )
Loop Control: Java Methods: <modifier(s)> <type> <method-name> ( [<type> param1] [, <type> param2] [, … ] )
3 types of expressions that A Java method can return a single value using a return statement: return <expression>; If a method
are used to control loops: will not return a value, the return type void is used in the method header. The return statement return;
may be used if needed or left out (causing an implicit return at the end of the method).
initialization ( init )
test void printHeadings( ) //no parameters, return type is void
update { <method body> }
Counter-controlled loops, void printDetailLine( String name, int number, double gpa )//33.141592635…
Math.PI parameters, return type is void
aka definite loops, work with { <method body> }
a loop control variable (lcv)
int getCount( ) //no parameters, return type is int
Sentinel-controlled loops, { <method body> }
aka indefinite loops, work
double max( double x, double y ) //2 parameters, return type is double
with a sentinel value
{ <method body> }
Java Loop Early Exit: When a method is called, the data is passed to the parameters (if any) using arguments
break statement
//Arguments: "Jack Wilson", 100, 3.50 passed to Parameters: name, number, gpa for Method:
Note: The break statement can printDetailLine (see method header above) : printDetailLine( "Jack Wilson", 100, 3.50);
be used with a switch
statement or a loop in A method may be declared with one variable length parameter. It must be the last parameter declared.
Java. Loops may also use The syntax of the declaration is <type> ... <parameter-name>. Spacing doesn’t matter.
a continue statement. Examples: int... numbers, double ... values, String ...names //implicit array creation