0
   

Is there quotient-function in java?

 
 
Reply Mon 21 May, 2012 09:04 am
Is there quotient-function in java?
It is used in following program:

import java.util.Scanner;

public class QuotientWithException {
public static int quotient(int number1, int number2) {
if (number2 == 0)
throw new ArithmeticException("Divisor cannot be zero");

return number1 / number2;
}

public static void main(String[] args) {
Scanner input = new Scanner(System.in);

// Prompt the user to enter two integers
System.out.print("Enter two integers: ");
int number1 = input.nextInt();
int number2 = input.nextInt();

try {
int result = quotient(number1, number2);
System.out.println(number1 + " / " + number2 + " is "
+ result);
}
catch (ArithmeticException ex) {
System.out.println("Exception: an integer " +
"cannot be divided by zero ");
}

System.out.println("Execution continues ...");
}
}

  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 1,311 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Is there quotient-function in java?
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 04/23/2024 at 11:46:04