-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDivision.java
42 lines (34 loc) · 1.09 KB
/
Division.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Division.java
import java.util.Scanner; // Needed for the scanner class
/**
This program demonstrates the if-else statement.
*/
public class Division
{
public static void main(String[] args)
{
double number1, number2; // Division operands
double quotient; // Result of division
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get the first number.
System.out.print("Enter a nubmer: ");
number1 = keyboard.nextDouble();
// Get the second number.
System.out.print("Enter another number: ");
number2 = keyboard.nextDouble();
if (number2 == 0)
{
System.out.println("Division by zero is not possible.");
System.out.println("Please run the program again and ");
System.out.println("enter a number other than zero.");
}
else
{
quotient = number1 / number2;
System.out.print("The quotient of " + number1);
System.out.print(" divided by " + number2);
System.out.println(" is " + quotient);
}
}
}