0% found this document useful (0 votes)
10 views16 pages

Ict Group 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views16 pages

Ict Group 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

JAVA MATH & JAVA BOOLEANS

Information
Communication
Technology
Presenter:
GROUP 3
Java Math
JAVA MATH
The Java Math class has many methods that allows you to
perform mathematical tasks on numbers.

Math.max(x,y) method can be used to find the highest value of x


and y:

Math.min(x,y) method can be used to find the lowest value of x


and y:

Math.sqrt(x) method returns the square root of x:


Examples: Output
Math.max
19

Math.min(x,y)

Math.sqrt

5.0
JAVA MATH
Math.abs(x) method returns the absolute (positive) value of x:

Example: Output

5.8
JAVA MATH
Math.abs(x) method returns the absolute (positive) value of x:

Example: Output
0.20723766988792802
0.33745757433198986
0.9816026349170999
To get more control over the random number, for
example, if you only want a random number between 0
and 100, you can use the following formula:
Java Booleans
JAVA Booleans
Java Booleans
Very often, in programming, you will
need a data type that can only have
one of two values, like:
YES / NO
ON / OFF
TRUE / FALSE
For this, Java has a boolean data
type, which can store true or false
values.
Boolean Values
A boolean type is declared with the boolean keyword and can only take
the values true or false:

Boolean Expression
A Boolean expression returns a boolean value: true or false.
This is useful to build logic, and find answers.
For example, you can use a comparison operator, such as the
greater than (>) operator, to find out if an expression (or a variable)
is true or false:

Or even easier:
In the examples below, we use the equal to (==) operator to
evaluate an expression:
Real Life Example

Let's think of a "real life example" where we need to find out if a person is
old enough to vote.
In the example below, we use the >= comparison operator to find out if the
age (25) is greater than OR equal to the voting age limit, which is set to 18:

OUTPUT:
true
Real Life Example

Output "Old enough to vote!" if myAge is greater than or equal to 18.


Otherwise output "Not old enough to vote.":

OUTPUT:
Old enough to vote!
Q&A
Thank You

You might also like