Chapter 7
Chapter 7
ii. Math.sqrt() Ans. Returns the square root value of the argument ( √ ).
iii. Math.cbrt() Ans. Returns the cube root value of the argument ( √ ).
iv. Math.random() Ans. Returns a double value greater than or equal to 0.0 and less than 1.0.
v. Math.round() Ans. Returns the closest int or long (as per the argument). If the argument type is
double, the return type is long. If the argument type is float, the return type is int. www.bhuvantechs.com
vi. Math.ceil() Ans. Returns the smallest integer that is greater than or equal to the argument.
i. 2 + 5∗ 3 Ans. Math.cbrt(Math.pow(x,2)+5*Math.pow(y,3))
v. √ − Ans. Math.cbrt(Math.pow(z,2)-Math.PI)
8. Write a program in Java to find the maximum of three numbers using Math.max() method.
Ans.
import java.util.Scanner;
www.bhuvantechs.com
10. Write a program to compute and display the value of expression: 1/x2+1/y3+1/z4 where, the values
of x, y and z are entered by the user.
Ans.
import java.util.Scanner;
public class FindSquareroot
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter value of x: ");
int x = in.nextInt();
System.out.print("Enter value of y: ");
int y = in.nextInt();
www.bhuvantechs.com
12. Write a program that accepts a number x and then prints: x0, x1, x2, x3, x4, x5
Ans. import java.util.Scanner;
public class FindSquareroot
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter value of x: ");
int x = in.nextInt();
www.bhuvantechs.com
int i=0;
double tot=0;
while (i<=5) {
tot=Math.pow(x,i);
System.out.println(" "+tot);
i=i+1;
}
}
}
ii. Store the value -3375 in a variable and print its cube root.
Ans. double min=-3375;
System.out.println(Math.cbrt(min));
iii. Store the value 999.99 in a variable and convert it into its closest integer that is greater than or
equal to 999.99.
Ans. double min=999.99;
System.out.println(Math.ceil(min));
14. Write a program in Java to compute the final velocity of a vehicle using the following formula:
V2 = u2 + 2as where, u = initial velocity, a = acceleration and s = distance covered; they are entered by
the user.
Ans.
import java.util.Scanner;
public class FindSquareroot
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter initial velocity: ");
double u = in.nextInt();
System.out.print("Enter acceleration: ");
double a = in.nextInt();
System.out.print("Enter distance: ");
double s = in.nextInt();
double v=0;
v=Math.pow(u,2)+2*a*s;
System.out.println("Final Velocity "+Math.pow(v,2));
}
}
www.bhuvantechs.com