Arithmetic operation by class and object in java

  • admin on February 4, 2019
  • Likes!
Hello friends! Welcome to my website
How to make a java programming for basic arithmetic operation by Class and Object in java programming and oops in java?
This java language programming is free all type of errors like compiler and runtime errors and this programming is tested to compile and then run the program code.
Here is only programming code only with their output.

 Class and object in java programming

import java.util.Scanner;
//test class
class test1 {
int a, b;
      // Methods or object for Addtion
public void addtion(int a, int b) {
int s = a + b;
             System.out.println (a + ” + ” + b + ” = ” + s);
      }
// Methods or object for Subtraction
      public void subtraction(int a, int b) {
int s = a – b;
System.out.println(a + ” – ” + b + ” = ” + s);
}
// Methods or object for Multiply
public void multiply(int a, int b) {
int s = a * b;
System.out.println( a + ” * ” + b + ” = ” + s);
}
       // Methods or object for divistion
public void divistion(double a, double b) {
double s = a / b;
System.out.println( a + ” / ” + b + ” = ” + s);
}
         // Methods or object for Remainder
public void remainder(int a, int b) {
int s = a % b;
System.out.println( a + ” % ” + b + ” = ” + s);
}
}
public class arithmetic {
public static void main(String[] args) {
             Scanner c = new Scanner(System.in);
             // Make Object of the class
test1 o = new test1();
//input
System.out.print(“Enter the frist number: “);
o.a= c.nextInt();
System.out.print(“Enter the secand number: “);
             o.b = c.nextInt();
          System.out.println(“Result: “)
o.addtion(o.a, o.b);
o.subtaction(o.a, o.b);
o.multiplay(o.a, o.b);
o.divistion(o.a, o.b);
o.remainder(o.a, o.b);
}
}
Output:
Enter the frist number: 5
Enter second Number: 4
Result:
5 + 4 = 9
5 – 4 = 1
5 * 4 = 20
5 / 4 = 1.25
5 % 4 = 1
Note: double is a type of variable that supports to decimal values.I Use double for Store division result

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any dought about this java programming code or input & output please comment below
If you have other question about java programming send an email by contacting us form are given on page right side.
Thank You!

Article Categories:
Programs in java

Leave a Reply

Your email address will not be published. Required fields are marked *