- A23.0
- B1112.0
- C32.0
- D24.0
Time Taken:
Correct Answer:
Wrong Answer:
Percentage: %
Let's analyze the given expression and the output of the Java Math functions:
Math.pow(36, 0.5) + Math.cbrt(125) + Math.ceil(4.2) + Math.floor(7.9)
The Math.pow(x, y) method returns x raised to the power of y.Math.pow(36, 0.5) calculates the square root of 36.√36 = 6.0
The Math.cbrt(x) method returns the cube root of x.Math.cbrt(125) calculates the cube root of 125.∛125 = 5.0
The Math.ceil(x) method returns the smallest integer greater than or equal to x.Math.ceil(4.2) returns the smallest integer greater than or equal to 4.2.Math.ceil(4.2) = 5.0
The Math.floor(x) method returns the largest integer less than or equal to x.Math.floor(7.9) returns the largest integer less than or equal to 7.9.Math.floor(7.9) = 7.0
Adding these values together:6.0 + 5.0 + 5.0 + 7.0 = 23.0
The output of the expression is: 23.0
Let's analyze the given Java code step by step to predict its output:
String str1 = "great";
String str2 = "minds";
System.out.println(str1.substring(0, 2).concat(str2.substring(1)));
System.out.println("WH" + (str1.substring(2).toUpperCase()));
System.out.println(str1.substring(0, 2).concat(str2.substring(1)));\
- str1.substring(0, 2) extracts a substring from str1 starting at index 0 up to, but not including, index 2.
For str1 = "great", str1.substring(0, 2) results in "gr".
- str2.substring(1) extracts a substring from str2 starting at index 1 to the end of the string.
For str2 = "minds", str2.substring(1) results in "inds".
- Concatenating these results:"gr".concat("inds") results in "grinds".
- Therefore, the first println statement prints "grinds".
System.out.println("WH" + (str1.substring(2).toUpperCase()));
- str1.substring(2) extracts a substring from str1 starting at index 2 to the end of the string.
For str1 = "great", str1.substring(2) results in "eat".
- str1.substring(2).toUpperCase() converts this substring to uppercase."eat".toUpperCase() results in "EAT".
- Concatenating "WH" with the result:"WH" + "EAT" results in "WHEAT".
- Therefore, the second println statement prints "WHEAT".
The output of the code is:
The parseLong() function is a member of the Long wrapper class.
parseLong() is a static method provided by the Long wrapper class in Java.String into a long value.a) Long wrapper class
Math.random()
Explanation:
Double.parseDouble() converts the string values "26.0" and "74.0" into double values.26.0 and 74.0 results in 100.0.
Explanation:
In Call by Value, the values of the actual parameters are copied to the formal parameters. Any changes made to the formal parameters do not affect the actual parameters.
nextLine()
Reason — nextLine() reads the input till the end of line so it can read a full sentence including spaces.
char check (int x)
Reason — The prototype of a function is written in the given syntax:
return_type method_name(arguments)
Thus, the method has the prototype given below:
char check (int x)
Pure method
Reason — A method which does not modify the value of variables is termed as a pure method.