0% found this document useful (0 votes)
389 views

9 Maths Functions

This document provides examples of using various Java Math functions including Math.max, Math.min, Math.ceil, Math.floor, Math.abs, Math.sqrt, and Math.pow. It gives the output or return values for each function when passed sample arguments. Examples include finding the maximum or minimum of two values, rounding values up or down, calculating absolute values, square roots, and exponents.

Uploaded by

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

9 Maths Functions

This document provides examples of using various Java Math functions including Math.max, Math.min, Math.ceil, Math.floor, Math.abs, Math.sqrt, and Math.pow. It gives the output or return values for each function when passed sample arguments. Examples include finding the maximum or minimum of two values, rounding values up or down, calculating absolute values, square roots, and exponents.

Uploaded by

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

Math functions

(g) What will the following functions return when executed?


(j) Math.max(-17, -19)
(ii) Math.ceil(7.8)
Ans. i) -17
ii) 8.0

2011 (ii) 
double b = -15.6;
double a = Math.rint (Math.abs (b));
System.out.println("a= " +a);

Ans. a =16.0
Maths.abs(-15.6) will give 15.6 and Math.rint(15.6) gives 16.0.

2012 (d) Give the output of the following program segment:


double x = 2.9, y = 2.5;
System.out.println(Math.min(Math.floor(x), y));
System.out.println(Math.max(Math.ceil(x), y));

Ans.
2.0
3.0
Explanation : Math.min(Math.floor(x), y) = Math.min ( 2.0, 2.5 ) = 2.0
Math.max(Math.ceil(x), y)) = Math.max ( 3.0, 2.5 ) = 3.0

2012 (e) Name the types of error (syntax, runtime or logical error) in each case given below:
(i) Division by a variable that contains a value of zero.
(ii) Multiplication operator used when the operation should be division.
(iii) Missing semicolon. [2]
Ans.
(i) Runtime Error
(ii) Logical Error
(iii) Syntax Error
h) If int n[] ={1, 2, 3, 5, 7, 9, 13, 16} what are the values of x and y?
x=Math.pow(n[4],n[2]);
y=Math.sqrt(n[5]+[7]);
Ans. n[4] is 7 and n[2] is 3. So, Math.pow(7,3) is 343.0.
n[5] is 9 and n[7] is 16. So Math.sqrt(9+16) will give 5.0.
Note that pow() and sqrt() return double values and not int values.

2014 (c) What are the final values stored in variables x and y below?
double a = - 6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a,b));
ans
( c) 6.0 15.0
2014 (j) What will be the output when the following code segments are executed?
(i) String s="1001";
int x=Integer.valueOf(s);
double y=Double.valueOf(s);
System.out.println("x="+x);
System.out.println("y="+y);
ans
(j) (i) x=1001
y=1001.0
2015 (e) (i) Name the mathematical function which is used to find sine of an angle given
in radians.
ans
(i)sin()

(b)
Give the output of the following Math functions :
(i) Math.ceil(4.2)
(ii) Math.abs(-4)
ans
(b)
(i) 5.0
(ii) 4

2017 (g) What are the values stored in variables r1 and r2:
(i) double r1 = Math.abs(Math.min(-2.83, -5.83));
(ii) double r2 = Math.sqrt(Math.floor(16.3));
ans
(g)
(i)
5.83
(ii)
4.0
2018 (c) Give the output of the following:
(i) Math.floor (-4.7)
(ii) Math.ceil(3.4) + Math.pow(2, 3)
ans
(c)
i. -5.0
ii. 12.0
2019 b) Give the output of the following code:
String P = "20", Q ="19";
int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);
ans
(b) 2019

(f)
Give the output of the following:
Math.sqrt(Math.max(9,16))

ans
(f) 4.0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy