KnowledgeBoat Logo
|
LoginJOIN NOW

Computer Applications

Write a menu driven program to perform the following operations as per user’s choice:

(i) To print the value of c=a²+2ab, where a varies from 1.0 to 20.0 with increment of 2.0 and b=3.0 is a constant.

(ii) To display the following pattern using for loop:

A
AB
ABC
ABCD
ABCDE

Display proper message for an invalid choice.

Java

Java Conditional Stmts

52 Likes

Answer

import java.util.Scanner;

public class KboatMenu
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Type 1 for Value of c");
        System.out.println("Type 2 for pattern");
        System.out.print("Enter your choice: ");

        int choice = in.nextInt();

        switch (choice) {
            case 1:
            final double b = 3.0;
            for (int a = 1; a <= 20; a += 2) {
                double c = Math.pow(a, 2) + 2 * a * b;
                System.out.println("Value of c when a is "
                        + a + " = " + c);
            }
            break;

            case 2:
            for (char i = 'A'; i <= 'E'; i++) {
                for (char j = 'A'; j <= i; j++) {
                    System.out.print(j);
                }
                System.out.println();
            }
            break;
            
            default:
            System.out.println("INVALID CHOICE");
        }
    }
}

Output

BlueJ output of Write a menu driven program to perform the following operations as per user’s choice: (i) To print the value of c=a²+2ab, where a varies from 1.0 to 20.0 with increment of 2.0 and b=3.0 is a constant. (ii) To display the following pattern using for loop: A AB ABC ABCD ABCDE Display proper message for an invalid choice.BlueJ output of Write a menu driven program to perform the following operations as per user’s choice: (i) To print the value of c=a²+2ab, where a varies from 1.0 to 20.0 with increment of 2.0 and b=3.0 is a constant. (ii) To display the following pattern using for loop: A AB ABC ABCD ABCDE Display proper message for an invalid choice.BlueJ output of Write a menu driven program to perform the following operations as per user’s choice: (i) To print the value of c=a²+2ab, where a varies from 1.0 to 20.0 with increment of 2.0 and b=3.0 is a constant. (ii) To display the following pattern using for loop: A AB ABC ABCD ABCDE Display proper message for an invalid choice.

Answered By

17 Likes


Related Questions