home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
suite.zip
/
pct.zip
/
java.ext
< prev
next >
Wrap
Text File
|
1999-12-20
|
3KB
|
120 lines
@Decision statements
%If, then, else
$// response is either OK or CANCEL depending
// on the button that the user pressed
if (response == OK) {
// code to perform OK action
} else {
// code to perform Cancel action
}
%If, then, else if, else (extended)
$int testscore;
char grade;
if (testscore >= 90) {
grade = 'A';
} else if (testscore >= 80) {
grade = 'B';
} else if (testscore >= 70) {
grade = 'C';
} else if (testscore >= 60) {
grade = 'D';
} else {
grade = 'F';
}
%If, then, else (compact)
$expression ? op1 : op2
// The ?: operator evaluates expression and returns op1 if it's true and op2 if it's false.
%Switch
$int month;
switch (month) {
case 1: System.out.println("January"); break;
case 2: System.out.println("February"); break;
case 3: System.out.println("March"); break;
case 4: System.out.println("April"); break;
case 5: System.out.println("May"); break;
case 6: System.out.println("June"); break;
case 7: System.out.println("July"); break;
case 8: System.out.println("August"); break;
case 9: System.out.println("September"); break;
case 10: System.out.println("October"); break;
case 11: System.out.println("November"); break;
case 12: System.out.println("December"); break;
default: System.out.println("Hey, that's not a valid month!"); break;
}
@Loops
%Do loop (x times)
$do {
. . .
} while (count++ < 6);
%While loop
$while (value != -1) {
count++;
System.out.println("Read a character. Count = " + count);
}
%For loop
$// "a" is an array of some kind
int i;
int length = a.length;
for (i = 0; i < length; i++) { //for (initialization; termination; increment)
// do something to the i th element of a
}
%Do while loop
$int c;
Reader in;
do {
c = in.read();
} while (c != -1);
@Exception Handling
%
$
@Branching statements
%
$
@Operators
%General list
$> greater than
>= greater than or equal to
< less than
<= less than or equal to
== are equal
!= are not equal
&& (op1 && op2) op1 and op2 are both true, conditionally evaluates op2
|| (op1 || op2) either op1 or op2 is true, conditionally evaluates op2
! (! op) op is false
& (op1 & op2) op1 and op2 are both true, always evaluates op1 and op2
| (op1 | op2) either op1 or op2 is true, always evaluates op1 and op2
%Assign a value
$i = i + 2;
//You can shorten this statement using the short cut operator +=.
//i += 2;
%Increment number
$count++; //or ++count;
%DeIncrement number
$count--; //or --count;
%
$
%
$
%
$
%
$
%
$
%
$
%
$
%
$
%
$