Advertisement
Guest User

ya

a guest
Feb 27th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. class Help {
  2. void helpon(int what) {
  3. switch(what) {
  4. case '1':
  5. System.out.println("The if:\n");
  6. System.out.println("if(condition) statement;");
  7. System.out.println("else statement;");
  8. break;
  9. case '2':
  10. System.out.println("The switch:\n");
  11. System.out.println("switch(expression) {");
  12. System.out.println(" case constant:");
  13. System.out.println(" statement sequence");
  14. System.out.println(" break;");
  15. System.out.println(" //...");
  16. System.out.println("}");
  17. break;
  18. case '3':
  19. System.out.println("The for:\n");
  20. System.out.println("for(init; condition; iteration)");
  21. System.out.println(" statement;");
  22. break;
  23. case '4':
  24. System.out.println("The while:\n");
  25. System.out.println("while(condition) statement;");
  26. break;
  27. case '5':
  28. System.out.println("The do-while:\n");
  29. System.out.println("do {");
  30. System.out.println(" statement;");
  31. System.out.println("} while(condition);");
  32. break;
  33. case '6':
  34. System.out.println("The break:\n");
  35. System.out.println("break; or break label;");
  36. break;
  37. case '7':
  38. System.out.println("The continue:\n");
  39. System.out.println("continue; or continue label;");
  40. break;
  41. }
  42. System.out.println();
  43. }
  44.  
  45. void showMenu() {
  46. System.out.println("Help on:");
  47. System.out.println(" 1. if");
  48. System.out.println(" 2. switch");
  49. System.out.println(" 3. for");
  50. System.out.println(" 4. while");
  51. System.out.println(" 5. do-while");
  52. System.out.println(" 6. break");
  53. System.out.println(" 7. continue\n");
  54. System.out.println("Choose one (q to quit): ");
  55. }
  56.  
  57. boolean isValid(int ch) {
  58. if(ch < '1' | ch > '7' & ch != 'q') return false;
  59. else return true;
  60. }
  61. }
  62.  
  63. class HelpClassDemo {
  64. public static void main(String args[])
  65. throws java.io.IOException {
  66. char choice, ignore;
  67. Help hlpobj = new Help();
  68.  
  69. for(;;) {
  70. do {
  71. hlpobj.showMenu();
  72. choice = (char) System.in.read();
  73. do {
  74. ignore = (char) System.in.read();
  75. } while ( !hlpobj.isValid(choice));
  76.  
  77. if(choice == 'q') break;
  78.  
  79. System.out.println("\n");
  80. hlpobj.helpOn(choice);
  81. }
  82. }
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement