You are on page 1of 2

WriteUp

Code Walkthrough:

1. The program begins with the package statement, which specifies the
package name as arithmeticcalculator.
2. The necessary packages are imported, including java.util.Scanner, which
allows user input from the console.
3. The arithmeticcalculator class is defined, and the main method is declared.
4. The program displays a menu of arithmetic operations to the user.
5. The program prompts the user to enter a choice from 1 to 4.
6. The user's choice is stored in the choice variable.
7. If the choice is within the valid range (1-4), the program proceeds to ask the
user for two numbers.
8. The program performs the selected arithmetic operation based on the
user's choice.
9. The result is stored in the res variable.
10.The program prints the result to the console.
11.If the user enters a choice other than 1, 2, 3, or 4, the program prints
"Invalid Choice!" to the console.

Algorithm:

1. Start:
2. Display "1. Addition" to the user.
3. Display "2. Subtraction" to the user.
4. Display "3. Multiplication" to the user.
5. Display "4. Division" to the user.
6. Prompt the user to enter their choice (1-4) and store it.
7. If the choice is within the range 1-4, then:
8. Prompt the user to enter the first number and store it.
9. Prompt the user to enter the second number and store it.
10. If the choice is 1, then add the two numbers.
11. If the choice is 2, then subtract the second number from the first.
12.If the choice is 3, then multiply the two numbers.
13. If the choice is 4, then divide the first number by the second number.
14. Display the result to the user.
15.If the choice is not within the range 1-4, then display "Invalid Choice!" to
the user.
16. End.

You might also like