zero_shubham1

ompiling_with_javac

Jun 25th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.*;
  3.  
  4. class calc{
  5. int result, operator1, operator2;
  6. char operand;
  7.  
  8. int add(int a, int b){
  9. return a+b;
  10. }
  11.  
  12. int sub(int a, int b){
  13. return a-b;
  14. }
  15.  
  16. public void calc(){
  17. Scanner in = new Scanner(System.in);
  18. System.out.println("\nEnter first operator: ");
  19. operator1 = in.nextInt();
  20. System.out.println("\nEnter second operator: ");
  21. operator2 = in.nextInt();
  22. System.out.println("\nEnter operand(options-> + - * /): ");
  23. operator2 = in.next().charAt(0);
  24.  
  25. System.out.println("\nCalculating.....");
  26.  
  27. switch(operand){
  28. case '+':
  29. result = add(operator1, operator2);
  30. System.out.println("\nResult:"+result);
  31. case '-':
  32. result = sub(operator1, operator2);
  33. System.out.println("\nResult:"+result);
  34.  
  35. default:
  36. System.out.println("\nWrong choice of operand!");
  37. }
  38. }
  39. }
  40.  
  41. class test{
  42. public static void main(String args[]){
  43. calc c1 = new calc();
  44. }
  45. }
Add Comment
Please, Sign In to add comment