Академический Документы
Профессиональный Документы
Культура Документы
Java Statement
Assign St.
Compound St. : var = exp : { }
Statement
Control
Loop St. : for St., while St., do-while St. Branch St. : break St., continue St., return St.
Exception Handling St.: try-catch-finally Synchronization St. : synchronized Standard I/O : System.in.read(), System.out.println()
Assignment Statement
Assign the value to variable Form : <variable> = <expression>
Type Conversion
[AssignmentSt.java]
Compound Statement
To give one statement grouping several statements Form
{ <declaration> or <statement> }
if (a > b) a--; b++;
[CompoundSt.java]
Local Variable
[AnotherBlock.java], [LocalVariable.java]
Control Statement
To change the execution order of program As the method of controlling the execution order
Conditional Statement : if St., switch St. Repeat Statement : for St., while St., do-while St. Branch Statemnt : break St., continue St., return St.
Form of if Statement
if ( <conditional expression> ) <statement> if ( < conditional expression > ) <statement1> else <statement2>
if (a < 0) a = -a; if (a > b) m = a; else m = b;
Nested if statement
if (<cond. expr.>) if (<cond. expr.>) // . . . <statement> if (<cond. expr.1>) <statement 1> else if (<cond. expr.2>) < statement 2> else if (<cond. expr. n>) < statement n> else < statement>
[NestedIf.java]
[SwitchSt.java], [SwitchSt2.java]
for ( <expr. 1> ; < expr. 2> ; < expr. 3>) <statement> <expr. 1> : initialize the control variable <expr. 2> : check the control variable <expr. 3> : modify the control variable
3 6
False
True
[ForSt.java]
[PrintMatrix.java]
Order of Execution
(1)
while (< Cond. Expr. >)
(4)
False
(2) True
< Statement >
(3)
do
<statement> while (<conditional expression>);
[DoWhile.java]
break [label] ;
int i = 1; while (true) { if (i == 3) break; System.out.println("This is a " + i + " iteration"); ++i; }
[BreakSt.java]
continue [Label] ;
[ContinueSt.java]
[LabeledContinue.java]
[ReturnSt.java]
Standard I/O
Standard Input File : in Standard Output File : out Standard Error File : err
Primitive Package of Java : java.io provides standard I/O Standard Input Method :
System.in.read()
Read a character from keyboard and return the integer type for that code value.
[SimpleIO.java], [CopyInputToOutput.java]