JAVA
~ Write a program to find all the arithmetic operations using switch case.
Answers
Solution:
Given code is written in Java.
import java.util.Scanner;
public class Switch_Case{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a, b, choice;
System.out.print("Enter first number: ");
a = sc.nextInt();
System.out.print("Enter second number: ");
b = sc.nextInt();
System.out.println("1. Addition.");
System.out.println("2.Subtraction.");
System.out.println("3. Multiplication.");
System.out.println("4. Division.");
System.out.println("5. Remainder.");
System.out.print("\nEnter your choice: ");
choice = sc.nextInt();
switch(choice){
case 1:
System.out.println("Result is: " + (a + b));
break;
case 2:
System.out.println("Result is: " + (a-b));
break;
case 3:
System.out.println("Result is: " + (a * b));
break;
case 4:
System.out.println("Result is: " + (a / b));
break;
case 5:
System.out.println("Result is: " + (a % b));
break;
default:
System.out.println("Invalid Input.");
}
}
}
Explanation:
- At first, we ask the user to enter two numbers.
- Then we ask the user to enter their choice.
- Based on the choice entered, the required operation is carried out using switch case.
- For an invalid input, an appropriate message is displayed.
Output is attached.
Explanation:
The General Assembly is the main deliberative, policymaking and representative organ of the UN. All 193 Member States of the UN are represented in the General Assembly, making it the only UN body with universal representation....