Advertisement
476179

IfElseStatment.D2

Oct 24th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package lessons;
  2. import java.util.Scanner;
  3. public class IfElseStatment
  4. {
  5. //write a program that handles "division by zero" programming problem.
  6. //prgm asks user for 2 numbers, if second number is 0 alert user div by 0 is not possible
  7. // otherwise divide and produce output
  8.  
  9. public static void main(String[] args)
  10. {
  11. Scanner keyboard = new Scanner(System.in);
  12.  
  13. System.out.println("this program will output ther quotent of the first number"+
  14. " divided by the second number.\nenter the first number:");
  15. double num1 = keyboard.nextDouble();
  16. System.out.println("enter the second number:");
  17. double num2 = keyboard.nextDouble();
  18.  
  19. if (num2 == 0)
  20. {
  21. System.out.println("Error. Division by 0 is not possible.");
  22.  
  23. }
  24. else
  25. {
  26. double quo3 = num1 / num2;
  27. System.out.println(quo3);
  28. }
  29.  
  30. keyboard.close();
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement