3-2 Division

posted Jan 19, 2014, 5:55 AM by Dlovan ismail   [ updated Jan 21, 2014, 12:44 PM by Karwan Jacksi ]

package division;
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 numberl, 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 number: ");
        numberl=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 =numberl / number2;
        System.out.print("The quotient of " + numberl );
        System.out.print(" divided by " + number2);
        System.out.println(" is " + quotient);
        }
    }    
}

ċ
Division.java
(1k)
Karwan Jacksi,
Jan 19, 2014, 5:55 AM
Comments