0% found this document useful (0 votes)
5 views2 pages

Java Scanner Example for Division

The document provides two examples of Java programs using the Scanner class to perform division. The first example performs a simple division, while the second example includes error handling for division by zero using a try-catch block. Both examples prompt the user for input and display the quotient or an error message if the divisor is zero.

Uploaded by

ponmanie5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Scanner Example for Division

The document provides two examples of Java programs using the Scanner class to perform division. The first example performs a simple division, while the second example includes error handling for division by zero using a try-catch block. Both examples prompt the user for input and display the quotient or an error message if the divisor is zero.

Uploaded by

ponmanie5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Scanner Example in java

import [Link];
public class JavaExample {

public static void main(String[] args) {

int num1, num2;


Scanner scan = new Scanner([Link]);
[Link]("Enter first number(dividend): ");
num1 = [Link]();

[Link]("Enter second number(divisor): ");


num2 = [Link]();

int div = num1/num2;


[Link]("Quotient: "+div);
}
}
Output:

Example:2

import [Link];
public class JavaExample {

public static void main(String[] args) {

int num1, num2;


Scanner scan = new Scanner([Link]);
[Link]("Enter first number(dividend): ");
num1 = [Link]();

[Link]("Enter second number(divisor): ");


num2 = [Link]();
try {
int div = num1 / num2;
[Link]("Quotient: "+div);
}catch(ArithmeticException e){
[Link]("Do not enter divisor as zero.");
[Link]("Error Message: "+e);
}

}
}
Output:

You might also like