Getting started with Java Applet
YY435
Pacific Network Academy
the next day
5, process control statement
The statement that can determine the execution order of other statements is called the flow control statement. There is a statement in the Java language:
Select judgment statement: IF-else, Switch-Case
Circular statement: for, while, do-while
Abnormal throw and capture statement: try-catch-finally, throw
Control statement: Break, Continue, Label:, Return
First, choose judgment statement
Two forms:
1. IF statement
IF (expression)
or
IF (condition), ELSE
They are cooked, such as:
IF (testscore> = 90) {grade = 'a';} else if (testscore> = 80) {grade = 'b';} else f (testscore> = 70) {grade = 'c';} else f Testscore> = 60) {grade = 'd';} else {grade = 'f';}
2, Switch statement
Switch (Expression or Variable) {CASE The first choice of possible: then ...; Break; Case second selection possible: then ...; Break; Case third selection possible: then ......; ... default: then Break;}
two. loop statement
1. FOR cycle
For (Initialization; Termination; Increment) Statements
2. While cycle
While (BooleaneXpression) Statements
3. Do-while loop
DO {statements }wide; booleaneXpression;
3. Transfer statement
1. Scriptomed statement format:
Number: SOMEJAVASTATEMENT;
2.BREAK statement
Break statement without a label: Terminate the execution of the current statement to move the control to the next statement of the current statement. BREAK statement with reference numerals: Terminate the label statement to make the control transfer to the next statement of the marker statement. Break StatementName ;
3.Continue statement
You can only use in a loop statement. Continue statement without a label: unconditional make the control to the condition determination section of the loop statement. Condinue statement with reference numerals: unconditionally transferred to the condition determination section of the loop statement of the band mark.
4. RETURN statement:
End the execution of the current method and return to the next statement of the call method statement. Return Expression; Return;
Ok, give you an example. as follows:
The source code of the program is as follows:
Import java.applet. *;
Import java.awt. *;
Public Class Applet1 Extends Applet
{
Public void Paint (Graphics G)
{
INT i = 1, J, N = 5;
While (i <= n)
{
For (j = 1; j <= i * 2-1; j )
g.drawstring ("*", (100
10 * J 10 * (N-I)), i * 20); i ;
}
}
}