Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- import java.util.Scanner;
- public class IfElseStatment
- {
- //write a program that handles "division by zero" programming problem.
- //prgm asks user for 2 numbers, if second number is 0 alert user div by 0 is not possible
- // otherwise divide and produce output
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- System.out.println("this program will output ther quotent of the first number"+
- " divided by the second number.\nenter the first number:");
- double num1 = keyboard.nextDouble();
- System.out.println("enter the second number:");
- double num2 = keyboard.nextDouble();
- if (num2 == 0)
- {
- System.out.println("Error. Division by 0 is not possible.");
- }
- else
- {
- double quo3 = num1 / num2;
- System.out.println(quo3);
- }
- keyboard.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement