Computer Applications
Explain Java function Math.pow( ) with an example.
Input in Java
7 Likes
Answer
In Java, Math.pow( ) function returns the value of the first argument raised to the power of the second argument.
Syntax
<Return data type> <variable> = Function name (argument 1, argument 2);
double <variable> = Math.pow(arg1, arg2);
For example, consider the statement
double d = Math.pow(3, 2);
It will raise 3 to the power of 2 (3 * 3) and return a double type value for d as 9.0.
Answered By
5 Likes
Related Questions
int a = 20, b=15; if ( a > 10 ) { a = a++; b++; } System.out.println( a + "," + b);
What will be the values of a and b when executed?
Mohit wanted to design a program using scanner class. Due to some confusion, he could not complete the program and has left some places marked with (i), (ii), (iii) and (iv) to be filled with the keywords/expression, as given below:
(i) java.util; class Sample { public static void main(String args[]) { (ii) num; Scanner inp = (iii) Scanner(System.in); System.out.println("Enter a number:"); num=(iv); if(n % 2 == 0): System.out.println("Even number"); else: System.out.println("Odd number"); } }
Help him to complete the program by answering the following questions:
(a) What keyword/expression will be filled in place of (i)?
(b) What keyword/expression will be filled in place of (ii)?
(c) What keyword/expression will be filled in place of (iii)?
(d) What keyword/expression will be filled in place of (iv)?
Explain Java function Math.sqrt( ) with an example.
Explain Java function Math.min( ) with an example.