Experiment 9
Experiment 9
Java Assignment-9
(a)WAP to read two numbers from the user and perform all arithmetic
operations on these numbers. Display any exception if occurring
while performing those operations.
Code:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int a,b;
Scanner sc=new Scanner(System.in);
try
{
System.out.println("Enter a and b: ");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("Addition: "+(a+b));
System.out.println("Substrction: "+(a-b));
System.out.println("Multplication: "+(a*b));
System.out.println("Division: "+(a/b));
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
}
}
Output: