KEMBAR78
Mathematical Function Prog | PDF
0% found this document useful (0 votes)
9 views3 pages

Mathematical Function Prog

It's a fun thing to read the book

Uploaded by

modgamer586
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)
9 views3 pages

Mathematical Function Prog

It's a fun thing to read the book

Uploaded by

modgamer586
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/ 3

MATHEMATICAL FUNCTION PROGRAMS

1. Square Root (sqrt)


Question (Code):
int num = 49;
System.out.println("Square root of " + num + " is " + Math.sqrt(num));
Answer (Output):
Square root of 49 is 7.0
2. Cube Root (cbrt)
Question (Code):
int num = 27;
System.out.println("Cube root of " + num + " is " + Math.cbrt(num));
Answer (Output):
Cube root of 27 is 3.0
3. Ceil
Question (Code):
double num = 9.3;
System.out.println("Ceil value of " + num + " is " + Math.ceil(num));
Answer (Output):
Ceil value of 9.3 is 10.0
4. Floor
Question (Code):
double num = 9.8;
System.out.println("Floor value of " + num + " is " + Math.floor(num));
Answer (Output):
Floor value of 9.8 is 9.0
5. Round
Question (Code):
double num = 7.6;
System.out.println("Round value of " + num + " is " + Math.round(num));
Answer (Output):
Round value of 7.6 is 8
6. Absolute Value (abs)
Question (Code):
int num = -45;
System.out.println("Absolute value of " + num + " is " + Math.abs(num));
Answer (Output):
Absolute value of -45 is 45
7. Maximum (max)
Question (Code):
int a = 75, b = 120;
System.out.println("Maximum of " + a + " and " + b + " is " + Math.max(a, b));
Answer (Output):
Maximum of 75 and 120 is 120
8. Minimum (min)
Question (Code):
int a = 15, b = 28;
System.out.println("Minimum of " + a + " and " + b + " is " + Math.min(a, b));
COMPUTER APPLICATIONS NOTES IX @SAMMYEDITH
Answer (Output):
Minimum of 15 and 28 is 15
9. Random
Question (Code):
System.out.println("Random number between 0 and 1 is " + Math.random());
Answer (Output Example):
Random number between 0 and 1 is 0.6745234
10.
class MathFunctionsDemo
{
public static void main(String args[])
{
// sqrt()
int num1 = 49;
System.out.println("Square root of " + num1 + " is " + Math.sqrt(num1));
// cbrt()
int num2 = 27;
System.out.println("Cube root of " + num2 + " is " + Math.cbrt(num2));
// ceil()
double num3 = 9.3;
System.out.println("Ceil value of " + num3 + " is " + Math.ceil(num3));
// floor()
double num4 = 9.8;
System.out.println("Floor value of " + num4 + " is " + Math.floor(num4));
// round()
double num5 = 7.6;
System.out.println("Round value of " + num5 + " is " + Math.round(num5));
// abs()
int num6 = -45;
System.out.println("Absolute value of " + num6 + " is " + Math.abs(num6));
// max()
int a = 75, b = 120;
System.out.println("Maximum of " + a + " and " + b + " is " + Math.max(a, b));
// min()
int c = 15, d = 28;
System.out.println("Minimum of " + c + " and " + d + " is " + Math.min(c, d));
// random()
System.out.println("Random number between 0 and 1 is " + Math.random());
}
}
Sample Output (Answer Style):
Square root of 49 is 7.0
Cube root of 27 is 3.0
Ceil value of 9.3 is 10.0
Floor value of 9.8 is 9.0
Round value of 7.6 is 8
Absolute value of -45 is 45
COMPUTER APPLICATIONS NOTES IX @SAMMYEDITH
Maximum of 75 and 120 is 120
Minimum of 15 and 28 is 15
Random number between 0 and 1 is 0.543627462

COMPUTER APPLICATIONS NOTES IX @SAMMYEDITH

You might also like