Skip to main content

//Function:- Arthmatic Operation

 Function Arthmatic Operation


CODE

๐Ÿ‘‡

  1. class funtion //class Declaration; class name same as file name...when save in local file.
  2. {
  3. public static void main(String args[]) 
  4. {
  5. int rs1,rs2,rs3,rs4,rs5;
  6. rs1 = add(30,20); //Calling the Function and Storing.
  7. System.out.println("the addition is:"+rs1);

  8.   rs2 = sub(30,20);
  9.         System.out.println("the subtraction is:"+rs2); // '+rs2' is used to indicate which value should be print.

  10.   rs3 = divi(30,20);
  11.         System.out.println("the division is:"+rs3); //"System.out.println" use for print line.

  12.   rs4 = multi(30,20);
  13.         System.out.println("the multiplication is:"+rs4); 

  14. rs5 = mod(30,20);
  15.         System.out.println("the modulos is:"+rs5); 

  16. }

  17. //Function Definition
  18. static int add(int a, int b)
  19. {
  20. int  c; //take new variable for store a result value.
  21. c = a + b;
  22. return c; // return c is returns the sum of the two parameters.
  23. }

  24. static int sub(int a, int b)
  25. {
  26.         int  c;
  27.         c = a - b;
  28. return c;
  29. }

  30. static int divi(int a, int b)
  31. {
  32.         int  c;
  33.         c = a / b;
  34. return c;
  35. }

  36. static int multi(int a, int b)
  37. {
  38.         int  c;
  39.         c = a * b;
  40. return c;
  41. }

  42. static int mod(int a, int b)
  43. {
  44.         int  c;
  45.         c = a % b;
  46. return c;
  47. }
  48. }


๐Ÿ‘‰Excute๐Ÿ‘ˆ


//Output

/*

the addition is:50

the subtraction is:10

the division is:1

the multiplication is:600

the modulos is:10

*/



                                                     //ThE ProFessoR