Menubased Program in JAVA : Syntax Help - 👑 सार्थक मुंड S3 🤴🏻

Menubased Program in JAVA : Syntax Help

Java Menubased Program

Write a program (WAP) in JAVA to Menu-based selection for know the syntax of While, do...while and for loop.

/* Java Program  - Java do-while Loop
 * Using a do-while loop to process a menu selection
 */
import java.util.Scanner;
public class JavaHelp
{  
  public static void main(String args[])
  {
    Scanner scan = new Scanner(System.in);
    char choice;
       
    do
    {
      System.out.println("Help on  Syntax : ");
      System.out.println("1. while");
      System.out.println("2. do-while");
      System.out.println("3. for");
      System.out.println("4. QUIT");
           
      System.out.println("Choose any one : ");
      choice = scan.next().charAt(0);
    }while(choice < '1' || choice > '3');
       
    System.out.println("\n");
       
    switch(choice)
    {  
      case '1' :
      System.out.println("The while :\n");
      System.out.println("while(condition)\n{");
      System.out.println("\t// body of loop\n}");
      break;
               
      case '2' :
      System.out.println("The do-while :\n");
      System.out.println("do\n{");
      System.out.println("\t// body of loop\n\n}while(condition);");
      break;
           
      case '3' :
      System.out.println("The for :\n");
      System.out.println("for(initialization; condition; iteration)\n{");
      System.out.println("\t// body of loop\n}");
      break;
           
      case '4' :
      System.exit(0);
      break;

      default :
      System.out.println("Invalid Choice");
    }
  }
}

 

Output
  When the above JAVA program is compiled or executed, it will produce the following results,
1. 
While Output

2.
do while Output

3. 
for output


Must Read :-

  1. Blogger Tutorial
  2. C Programs
  3. C++ Programs
  4. Java Programs
  5. Python Programs
  6. Programming Notes 
  7. Questions & Answers
  8. My Codes : HTML, CSS & JS
Previous article
Next article

Leave Comments

Post a Comment

Articles Ads

Articles Ads 1

Articles Ads 2

Advertisement Ads