zudi
Sales Funnel Architect
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
In this tutorial, you will learn on how to use Predefined Method. In java, predefined methods are organized as a collection of classes, called class libraries. For example, the class Math contains mathematical methods. The method type is the data type of the value returned by the method. The class Math is contained in the package java.lang
. I will be using the JCreator IDE in developing the program.
To start in this tutorial, first open the JCreator IDE, click new and paste the following code.
Sample run:
Uppercase is A
4.2 to the power of 3.0 = 74.09
5 to the power of 4 = 625.00
u = 31.20
The absolute value of -15=15
This program works as follows:
The statement
outputs the uppercase letter that corresponds to ‘a’, which is ‘A’.
In the statement
, the method pow (of the class Math) is used to output u. The method pow
is called with the parameters u and v. in this case, the values of u and v are passed to the method pow
The statement
uses the method pow
to output 5 to the power of 4.
The statement u =
u +
Math
.pow
(
3
, 3
)
;
uses the methodpow
to determine 3 to the power of 3, adds this value to the value of u, and then stores the new value into u.
The statement System
.out
.printf
(
"u = %.2f%n"
, u)
;
outputs the value of u.
The statement x =
-
15
;
stores -15 to x, and the statement
outputs the value of x.
. I will be using the JCreator IDE in developing the program.
To start in this tutorial, first open the JCreator IDE, click new and paste the following code.
- import
static
java.lang
.Math
.*;
- import
static
java.lang
.Character
.*;
- public
class
PredefinedMethod
- {
- public
static
void
main(
String
[
]
args)
- {
- int
x;
- double
u, v;
- System
.out
.println
(
"Uppercase a is "
- +
toUpperCase(
'a'
)
)
;
- u =
4.2
;
- v =
3.0
;
- System
.out
.printf
(
"%.1f to the power of "
- +
"%.1f = %.2f%n"
, u, v, pow(
u,v)
)
;
- System
.out
.printf
(
"5 to the power of 4 = "
- +
"%.2f%n"
, pow(
5
, 4
)
)
;
- u =
u +
Math
.pow
(
3
, 3
)
;
- System
.out
.printf
(
"u = %.2f%n"
, u)
;
- x =
-
15
;
- System
.out
.printf
(
"The absoloute value of %d = "
- +
"%d%n"
, x, abs(
x)
)
;
- }
- }
Sample run:
Uppercase is A
4.2 to the power of 3.0 = 74.09
5 to the power of 4 = 625.00
u = 31.20
The absolute value of -15=15
This program works as follows:
The statement
- System
.out
.println
(
"Uppercase a is "
- +
toUpperCase(
'a'
)
)
;
outputs the uppercase letter that corresponds to ‘a’, which is ‘A’.
In the statement
- System
.out
.printf
(
"%.1f to the power of "
- +
"%.1f = %.2f%n"
, u, v, pow(
u,v)
)
;
, the method pow (of the class Math) is used to output u. The method pow
is called with the parameters u and v. in this case, the values of u and v are passed to the method pow
The statement
- System
.out
.printf
(
"5 to the power of 4 = "
- +
"%.2f%n"
, pow(
5
, 4
)
)
;
uses the method pow
to output 5 to the power of 4.
The statement u =
u +
Math
.pow
(
3
, 3
)
;
uses the methodpow
to determine 3 to the power of 3, adds this value to the value of u, and then stores the new value into u.
The statement System
.out
.printf
(
"u = %.2f%n"
, u)
;
outputs the value of u.
The statement x =
-
15
;
stores -15 to x, and the statement
- System
.out
.printf
(
"The absoloute value of %d = "
- +
"%d%n"
, x, abs(
x)
)
;
outputs the value of x.