Answer to Question #224064 in Java | JSP | JSF for Swastika

Question #224064

Write a program ―DivideByZeroǁ that takes two numbers a and b as input,

computes a/b, and invokes Arithmetic Exception to generate a message when the

denominator is zero.


1
Expert's answer
2021-08-07T03:28:35-0400
import java.util.Scanner;


public class DivideByZero {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter a: ");
        double a=input.nextDouble();
        System.out.print("Enter a: ");
        double b=input.nextDouble();
        try{
          double result =a/b;  
          System.out.println("a/b = "+a+"/"+b+" = "+result);
        }catch(ArithmeticException ex){
          System.out.println("Division by zero");
        }
        
        input.close();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS