Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. => Make Calculator in Java.
  2. --------------------------------------------------
  3. import java.util.Scanner;
  4.  
  5. public class Calculator {
  6. public static void main(String[] args) {
  7.  
  8. int a,b, res;
  9. char choice, ch;
  10.  
  11. Scanner sc=new Scanner(System.in);
  12.  
  13. System.out.println("Here are our option");
  14. System.out.println("1. Addition");
  15. System.out.println("2. Subtraction");
  16. System.out.println("3. Division");
  17. System.out.println("4. Multiplication");
  18.  
  19. System.out.println("Enter your choice");
  20.  
  21. choice=sc.next().charAt(0);
  22.  
  23. switch(choice)
  24. {
  25. case '1': System.out.println("Enter any two number");
  26. a=sc.nextInt();
  27. b=sc.nextInt();
  28. res=a+b;
  29. System.out.println("Your Result is="+" "+res);
  30. break;
  31.  
  32. case '2': System.out.println("Enter any two number");
  33. a=sc.nextInt();
  34. b=sc.nextInt();
  35. res=a-b;
  36. System.out.println("Your Result is="+" "+res);
  37. break;
  38.  
  39. case '3': System.out.println("Enter any two number");
  40. a=sc.nextInt();
  41. b=sc.nextInt();
  42. res=a/b;
  43. System.out.println("Your Result is="+" "+res);
  44. break;
  45.  
  46. case '4': System.out.println("Enter any two number");
  47. a=sc.nextInt();
  48. b=sc.nextInt();
  49. res=a*b;
  50. System.out.println("Your Result is="+" "+res);
  51. break;
  52. }
  53. System.out.println("------------------------------------------");
  54.  
  55. }
  56. }
  57.  
  58. -----------------------------------------------------------------------------------
  59. When the above Java Program is compile and executed, it will produce the following output:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement