Sunteți pe pagina 1din 24

General programming and decision

making in Java
Compound statements
Multiple statements that are written
within curly brackets are called
compound statements
Java packages
Math.sqrt()
Find the square root of a positive
number
Returns double type value
Syntax
<return type> <variable> = function
name(positive number);
Example
double n = Math.sqrt(5);
Java packages
Math.min()
Find the minimum of two numbers
Returns type is according to the input

Syntax
<return type> <variable> = function
name(number1,number 2);
Example
double n = Math.min(5,2);
Java packages
Math.min()
Find the maximum of two numbers
Returns type is according to the input

Syntax
<return type> <variable> = function
name(number1,number 2);
Example
double n = Math.max(5,2);
Java packages
Math.pow()
Find the power raised to a base
Returns double type value

Syntax
<return type> <variable> = function
name(number1,number 2);
Example
double n = Math.pow(5,2);
Java packages
Math.log()
Find the logarithmic value of a given
number
Returns double type value
Syntax
<return type> <variable> = function
name(positive number);
Example
double n = Math.log(6.25);
Java packages
Math.round()
Returns the value in rounded form
Returns integer type always

Syntax
<return type> <variable> = function
name(positive number);
Example
double n = Math.round(5.7);
Java packages
Math.floor()
Returns a number down to the
nearest integer
Returns double type value always
Syntax
<return type> <variable> = function
name(positive number);
Example
double n = Math.floor(5.9);
Java packages
Math.ceil()
Returns rounded value to the next higher
integer
Returns double type value

Syntax
<return type> <variable> = function
name(positive number);
Example
double n = Math.sqrt(5.8);
Java packages
Math.sin() , Math.cos(), Math.tan()
Find the sin, cos and tan values
Returns double type value
Syntax
<return type> <variable> = function
name(positive number);
Example
double n = Math.sin(x);
double n = Math.cos(x);
double n = Math.tan(x);

S-ar putea să vă placă și