Lab4 2
Lab4 2
LABORATORY – 4
----------------------------------------------------------------------------------
Problem#1: Write a Java program that takes row number from the user and creates
the pattern given below with desired number of rows. The program should be written
using inner for loops and only the variable that is given by the user should be used
other than iteration variables.
Problem#2: Write a Java program that acts as a simple calculator. The program
should display a menu to the user with the following options:
1. Subtract
2. Add
3. Divide
4. Multiply
5. Exit
The program should perform the following tasks:
1. Prompt the user to select an option from the menu.
2. Based on the user's choice:
o If the user selects Subtract, ask for two numbers and display their difference.
o If the user selects Add, ask for two numbers and display their sum.
o If the user selects Divide, ask for two numbers and display their quotient.
Ensure that division by zero is not allowed and display an appropriate error
message if the second number is zero.
o If the user selects Multiply, ask for two numbers and display their product.
o If the user selects Exit, terminate the program with a goodbye message.
o For any invalid input, display an error message and prompt the user again.
3. Allow the user to perform multiple operations until they choose to exit.
Use a switch statement to handle the menu options and a while loop to keep the
program running until the user chooses to exit.