FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 229   



This is a simple Java program shows you the basic Mathematical operations using Integers & Floating point numbers

public class BasicMaths {

    public static void main(String[] args) {
        int i = 4;
        int j = 2;
        System.out.println("sum:" + (i + j));
        System.out.println("sub:" + (i - j));
        System.out.println("mul:" + (i * j));
        System.out.println("div:" + (i / j));
        System.out.println("remainder:" + (i % j));

        float f1 = 1.5f;
        float f2 = 1.2f;
        System.out.println("sum:" + (f1 + f2));
        System.out.println("sub:" + (f1 - f2));
        System.out.println("mul:" + (f1 * f2));
        System.out.println("div:" + (f1 / f2));
        System.out.println("remainder:" + (f1 % f2));
    }
}

Output

sum:6
sub:2
mul:8
div:2
remainder:0
sum:2.7
sub:0.29999995
mul:1.8000001
div:1.25
remainder:0.29999995



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News