Page 101 - CA_Blue( J )_Class10
P. 101
06 MATHEMATICAL LIBRARY
METHODS
Learning Objectives
6.1 Different Mathematical Methods
In Java, we can use different types of logic to solve a given task. One of the ways is using a method. In method, program
code is written to perform a specific task required or solve a problem. The main advantage of using a method is that a
method can be reused as and when required. We can also easily modify it according to our needs. There are two types
of methods in Java:
• User-defined Methods: These methods are created by programmers according to the needs of the program. You
will learn more about user-defined methods later in this book.
• Library/System Methods: These methods are already defined in the Java compiler and kept in some classes. Classes
are further grouped in some packages. You just need to import the desired package before using its classes and their
methods.
Java provides a wide variety of packages that contain a huge library of built-in classes. These classes provide different
types of pre-defined methods which are also known as library methods. For example, string methods, mathematical
methods, graphics methods, etc. In this chapter, we will learn about different types of mathematical methods that are
used frequently in coding.
6.1 DIFFERENT MATHEMATICAL METHODS
The Math class in Java provides different types of mathematical methods. To use mathematical methods in a program,
we just need to import the “java.lang” package in which the “Math” class is present. After importing the Math class,
we can use its methods in our program by using the following syntax:
Math.function_name(arguments);
Let us learn about some of the commonly used methods of the Math class.
6.1.1 The Math.min( ) Method
The Math.min( ) method is used to find the minimum number between two arguments passed to it. The return type of
the method depends on the type of arguments that are passed. For example, if both the arguments are integers, then
it returns an integer value. If both are double, then it returns a double value. On the other hand, if both the arguments
99
Mathematical Library Methods 99

