Which of the following expressions represents , where x, k, and j are properly declared…
- User
Which of the following expressions represents , where x, k, and j are properly declared and initialized int variables?
Responses
Math.abs(k - j, Math.pow(x));
Math.abs(k - j, Math.pow(x));
Math.abs(Math.pow(x), k - j);
Math.abs(Math.pow(x), k - j);
Math.pow(x, Math.abs(k - j));
Math.pow(x, Math.abs(k - j));
Math.pow(Math.abs(k - j), x);
Math.pow(Math.abs(k - j), x);
Math.pow.abs(x, k - j));
- Assistant
None of the expressions listed represents the given equation.
- User
Which of the following expressions represents , where x, k, and j are properly declared and initialized int variables?
Responses
Math.abs(k - j, Math.pow(x));
Math.abs(k - j, Math.pow(x));
Math.abs(Math.pow(x), k - j);
Math.abs(Math.pow(x), k - j);
Math.pow(x, Math.abs(k - j));
Math.pow(x, Math.abs(k - j));
Math.pow(Math.abs(k - j), x);
Math.pow(Math.abs(k - j), x);
Math.pow.abs(x, k - j));
- Assistant
The expression that represents is: Math.pow(x, Math.abs(k - j));
- User
The code segment below is intended to randomly print one of the values 2, 4, 6, or 8 with equal probability.
int val = /* missing code */ ;
val *= 2;
System.out.print(val);
Which of the following can be used to replace /* missing code */ so that the code segment works as intended?
Responses
Math.random() * 4 + 1
Math.random() * 4 + 1
Math.random() * 8
Math.random() * 8
(int) (Math.random() * 4)
(int) (Math.random() * 4)
(int) (Math.random() * 4 + 1)
(int) (Math.random() * 4 + 1)
(int) (Math.random() * 8 + 1)
- Assistant
To randomly print one of the values 2, 4, 6, or 8 with equal probability, the correct replacement for /* missing code */ would be:
(int) (Math.random() * 4) + 1
This expression generates a random number between 0 and 3 inclusive, and then adds 1 to the result to get values in the range of 1 to 4 inclusive.
- User
The code segment below is intended to randomly print one of the values 2, 4, 6, or 8 with equal probability.
int val = /* missing code */ ;
val *= 2;
System.out.print(val);
Which of the following can be used to replace /* missing code */ so that the code segment works as intended?
Responses
Math.random() * 4 + 1
Math.random() * 4 + 1
Math.random() * 8
Math.random() * 8
(int) (Math.random() * 4)
(int) (Math.random() * 4)
(int) (Math.random() * 4 + 1)
(int) (Math.random() * 4 + 1)
(int) (Math.random() * 8 + 1)
- Assistant
To randomly print one of the values 2, 4, 6, or 8 with equal probability, the correct replacement for /* missing code */ would be:
(int) (Math.random() * 4) + 1
This expression generates a random number between 0 and 3 inclusive, and then adds 1 to the result to get values in the range of 1 to 4 inclusive. Multiplied by 2, this will give the desired values of 2, 4, 6, or 8.
- User
Given the following code segment.
double s;
Assume s has been properly initialized to a double value. The area of a square is its side length times itself.
Which of the following statements can be used to compute the area of a square whose side length is s units?
Responses
pow(s, 2);
pow(s, 2);
s.pow(2);
s.pow(2);
Math.pow(s);
Math.pow(s);
Math.pow(s, 2);
Math.pow(s, 2);
Math.pow(2, s);
- Assistant
To compute the area of a square whose side length is s units, the correct statement would be:
Math.pow(s, 2);
This uses the Math.pow() method to raise the value of s to the power of 2, giving us the area of the square.