Hỗ trợ lập trình Java
Hãy đăng nhập để tham gia thảo luận và chia sẻ!
Hỗ trợ lập trình Java
Hãy đăng nhập để tham gia thảo luận và chia sẻ!
Hỗ trợ lập trình Java

Diễn đàn hỏi đáp Java, hướng dẫn bài tập Java, Giúp đỡ về Java


You are not connected. Please login or register

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down  Thông điệp [Trang 1 trong tổng số 1 trang]

1Bài 5 - TH Java Empty Bài 5 - TH Java Sun Nov 04, 2012 3:59 pm

Admin


Admin
Admin
Bài 5: xây dựng menu help
Code:
import java.util.Scanner;


public class Help {
   String choose;
   boolean check;
   public Help() {
      choose = "";
      check = false;
   }
   public void menu() {
      System.out.println("1.if");
      System.out.println("2.switch");
      System.out.println("3.for");
      System.out.println("4.while");
      System.out.println("5.do-while");
      System.out.println("6.break");
      System.out.println("7.continute");
   }
   public void userChoose() {
      Scanner inp = new Scanner(System.in);
      System.out.print("Choose one (q to quit): ");
      choose = inp.nextLine();
   }
   public void printStament(String select) {
      switch(select){
      case "1":
         System.out.println("--if(condition) stament\nelse stament--");
         break;
      case "2":
         System.out.println("--switch(variable) {case ... : stament\ndefault: stament\n}--");
         break;
      case "3":
         System.out.println("--for(init_var;condition;next_var) stament--");
         break;
      case "4":
         System.out.println("--while(condition) stament--");
         break;
      case "5":
         System.out.println("--do stament while(condition)--");
         break;
      case "6":
         System.out.println("--stop and escapse a loop or a switch stament--");
         break;
      case "7":
         System.out.println("--continute is a command to skip all command follow in a loop--");
         break;
      case "q":
         check = true;
      }
   }
   public static void main( String args[] ) {
      Help object = new Help();
      while (!object.check){
         object.menu();
         object.userChoose();
         object.printStament(object.choose);
      }
      System.out.println("Ban da thoat khoi chuong trinh !!");
   
   }
}

(Write by MRKHOA92)

https://javasupport.forumvi.com

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang  Thông điệp [Trang 1 trong tổng số 1 trang]

Permissions in this forum:
Bạn không có quyền trả lời bài viết