Programming Shortcut

Write, Run and execute Your programs with simple and esay way by Programming Shortcut

Monday, February 4, 2019

Arithmetic operation by class and object in java

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


// -----Start Code -----
    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 Addtion
        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);
    }
}
//----- code end -----

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!

Programming Shortcut is collections in java best programs with example, best c programs with example and best c++ programs with example, best way to learn java, c and c++

About Programming Shortcut

This is a programming learning website that can help you learn and when your write your programming code. And all programming code is compiled run programming code in the following programming language C, c++, Java, php and Javascript Languages. find your programming read, understand the programming then copy and past and run your program and save your golden time to typing the program becuse you learn more in leas time. All Programming is codeing is ease to understand the programming