home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / suite.zip / pct.zip / java.ext < prev    next >
Text File  |  1999-12-20  |  3KB  |  120 lines

  1. @Decision statements
  2. %If, then, else
  3. $// response is either OK or CANCEL depending
  4. // on the button that the user pressed
  5. if (response == OK) {
  6.     // code to perform OK action
  7. } else {
  8.     // code to perform Cancel action
  9. }
  10. %If, then, else if, else (extended)
  11. $int testscore;
  12. char grade;
  13. if (testscore >= 90) {
  14.     grade = 'A';
  15. } else if (testscore >= 80) {
  16.     grade = 'B';
  17. } else if (testscore >= 70) {
  18.     grade = 'C';
  19. } else if (testscore >= 60) {
  20.     grade = 'D';
  21. } else {
  22.     grade = 'F';
  23. }
  24. %If, then, else (compact)
  25. $expression ? op1 : op2
  26. // The ?: operator evaluates expression and returns op1 if it's true and op2 if it's false.
  27. %Switch
  28. $int month;
  29. switch (month) {
  30. case 1:  System.out.println("January"); break;
  31. case 2:  System.out.println("February"); break;
  32. case 3:  System.out.println("March"); break;
  33. case 4:  System.out.println("April"); break;
  34. case 5:  System.out.println("May"); break;
  35. case 6:  System.out.println("June"); break;
  36. case 7:  System.out.println("July"); break;
  37. case 8:  System.out.println("August"); break;
  38. case 9:  System.out.println("September"); break;
  39. case 10: System.out.println("October"); break;
  40. case 11: System.out.println("November"); break;
  41. case 12: System.out.println("December"); break;
  42. default: System.out.println("Hey, that's not a valid month!"); break;
  43. }
  44.  
  45. @Loops
  46. %Do loop (x times)
  47. $do {
  48.     . . .
  49.     } while (count++ < 6);
  50. %While loop
  51. $while (value != -1) {
  52.     count++;
  53.     System.out.println("Read a character. Count = " + count);
  54. }
  55. %For loop
  56. $// "a" is an array of some kind
  57. int i;
  58. int length = a.length;
  59. for (i = 0; i < length; i++) {    //for (initialization; termination; increment)
  60.     // do something to the i th element of a
  61. }
  62. %Do while loop
  63. $int c;
  64. Reader in;
  65. do {
  66.     c = in.read();
  67. } while (c != -1);
  68.  
  69. @Exception Handling
  70. %
  71. $
  72.  
  73. @Branching statements
  74. %
  75. $
  76.  
  77.  
  78.  
  79.  
  80.  
  81. @Operators
  82. %General list
  83. $>  greater than
  84. >= greater than or equal to
  85. <  less than
  86. <= less than or equal to
  87. == are equal
  88. != are not equal
  89. && (op1 && op2)    op1 and op2 are both true, conditionally evaluates op2 
  90. || (op1 || op2)    either op1 or op2 is true, conditionally evaluates op2 
  91. !  (! op)        op is false 
  92. &  (op1 & op2)    op1 and op2 are both true, always evaluates op1 and op2 
  93. |  (op1 | op2)    either op1 or op2 is true, always evaluates op1 and op2 
  94. %Assign a value
  95. $i = i + 2;
  96. //You can shorten this statement using the short cut operator +=. 
  97. //i += 2;
  98. %Increment number
  99. $count++; //or ++count;
  100. %DeIncrement number
  101. $count--; //or --count;
  102. %
  103. $
  104. %
  105. $
  106. %
  107. $
  108. %
  109. $
  110. %
  111. $
  112. %
  113. $
  114. %
  115. $
  116. %
  117. $
  118. %
  119. $
  120.