Java
Java
Java
Solution:
Code:
import java.util.Scanner;
try {
@SuppressWarnings("resource")
Scanner reader = new Scanner(System.in);
System.out.print("Enter First number : ");
double first = reader.nextDouble();
System.out.print("Enter Second number :");
double second = reader.nextDouble();
System.out.println(" ");
System.out.println("Enter an operator");
System.out.println("Press 1 : Addintion");
System.out.println("Press 2 : Subtraction");
System.out.println("Press 3 : Multiplication");
System.out.println("Press 4 : Division): ");
char operator = reader.next().charAt(0);
double result;
switch(operator)
{
case '1':
result = first + second;
break;
case '2':
result = first - second;
break;
case '3':
result = first * second;
break;
case '4':
result = first / second;
break;
Output:
PRACTICAL NO.2
Question 2: implement a program using custom exception in java to handle user created
exception and use all the five keywords of exception handling mechanism
Solution:
Code:
Output: