Java Basic Problems

Java: Multiplication and Division of Float variables by defining and using static methods

 

In my last post I have shared about How to sort string in alphabetical order in array. 

Today I am sharing a new idea.

 

Static methods can be called without using the objects. They are also available for use by other classes.

In this example, I have used two float variables and passed them to another class for multiplication and division operation.

Here is the Code example:
class MathOperation

{

static float mul(float x, float y)

{

return x*y;

}

static float divide(float x, float y)

{

return x/y;

}

}

class MathApplication

{

public  static void main(String args[])

{

System.out.println(“\n”);

float a = MathOperation.mul(4.0f,5.0f);

System.out.println(“Result After Multiplication of Float Values=”+a);

float b = MathOperation.divide(a,2.0f);

System.out.println(“\n”);

System.out.println(“Result After Division of Float Values=”+b);

System.out.println(“\n”);

}

}

 OUTPUT:

multiplication and division float values java

1 thought on “Java: Multiplication and Division of Float variables by defining and using static methods”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s