Question

In: Computer Science

If x=3, y=4 what is the value of this Java expression? (double) (x/y) What is the...

If x=3, y=4 what is the value of this Java expression?

(double) (x/y)

What is the value of this Java expression?

(int)(1.0 / 2.0) + (double)(1 / 2)

True or False:

(double)(x)/y is the same as double (x/y)

What is the value of this Java expression?

(double)3  

Solutions

Expert Solution

Q1

If x=3, y=4 what is the value of this Java expression?

(double) (x/y)

The value will be 0.0 because first the expression x/y is evaluated as integer then 3/4 because x and y both are integers there will be no upcasting. Hence it will be equal to 0

Q2

What is the value of this Java expression?

(int)(1.0 / 2.0) + (double)(1 / 2)

Similar to above the value will be 0+ 0.0 = 0 because the 1.0 and 2.0 both are floats and the result will be 0.5 which is downcasted to int and results in 0 and 1/2 also becomes 0 because of integer division

Q3

(double)(x)/y is the same as double (x/y)

False as typecasting will be done before division in first case and in the second case after the division which can lead to different results as in case of x=1 and y=2

First will yield 0.5 and second will yield 0

Q4

What is the value of this Java expression?

(double)3  

3.0 as it is typecasted to a double


Related Solutions

if x is 2/3 of y and y is 3/4 of z, what is the value of z:x
if x is 2/3 of y and y is 3/4 of z, what is the value of z:x
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** *...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** * Create a point with coordinates <code>(0, 0)</code>. */ public Point2() { complete JAVA code this.set(0.0, 0.0); COMPLETE CODE }    /** * Create a point with coordinates <code>(newX, newY)</code>. * * @param newX the x-coordinate of the point * @param newY the y-coordinate of the point */ public Point2(double newX, double newY) { complete Java code this.set(newX, newY); }    /** * Create a...
Y varies directly as the square of X. If Y = 144 when X = 6, what is the value of y when x = 3
Y varies directly as the square of x. If y = 144 when x = 6, what is the value of ywhen x = 3
Solve this differential equation y''+(-4-2-2)y'+(4+4+4+4)y=x y(0)=3-2 y'(0)=2-3 Answer it as y(x)=... and motivate all the steps...
Solve this differential equation y''+(-4-2-2)y'+(4+4+4+4)y=x y(0)=3-2 y'(0)=2-3 Answer it as y(x)=... and motivate all the steps of the calculation
java Define the Circle2D class that contains: • Two double data fields named x and y...
java Define the Circle2D class that contains: • Two double data fields named x and y that specify the center of the circle with get methods. A data field radius with a get method. • A data field radius with a get method. • A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. • A constructor that creates a circle with the specified x, y, and radius. • A method getArea()...
what is the derivative of y=e^x/(3x+1)^4(x+1)^3
what is the derivative of y=e^x/(3x+1)^4(x+1)^3
1. What is the highest value of x that satisfies this equation x(x+4) = -3
  1. What is the highest value of x that satisfies this equation x(x+4) = -3 A. -1 B. 0 C. 1 D. -3 2. If x2 - 9x = -18, what are the possible values of x? A. -3 and -6 B. -3 and 6 C. 3 and -6 D. 3 and 6 3. What polynomial can be added to 2x2 - 2x+6 so that the sum is 3x2+ 7x? A. 5x2+ 5x+ 6 B. 4x2+ 5x+ 6 C....
Use the techniques of Chapter 4 to sketch the graph of y= x^4/4+x^3/3-x^2.   a) domain, b)...
Use the techniques of Chapter 4 to sketch the graph of y= x^4/4+x^3/3-x^2.   a) domain, b) y-intercept, c) asymptote(s), d) intervals of increase and/or decrease, e) local maximum(s) and/or local minimum(s), f) intervals of concavity, g) points of inflection. (For full credit, remember to show all work and include sign charts for the Increasing/Decreasing and 2nd Derivative tests.)
Consider the second-order boundary value problem y′′ +(2x^2 +3)y′ −y =6x, 0≤x ≤1, (4) y(0) =...
Consider the second-order boundary value problem y′′ +(2x^2 +3)y′ −y =6x, 0≤x ≤1, (4) y(0) = 1, y(1) = 0. (a) Rewrite the second-order equation (4) as a system of two first-order equations involving variables y and z. [2] (b) Suppose that yn and zn are approximations to y(xn) and z(xn), respectively, where xn = nh, n = 0,...,N and h = 1/N for some positive integer N. Find the iterative formula when using the modified Euler method to approximate...
Let u(x, y) = x^3 + kxy^2 + y. (a) Determine the value of k such...
Let u(x, y) = x^3 + kxy^2 + y. (a) Determine the value of k such that u is an harmonic function. (b) Find the harmonic conjugate v of u. (c) Obtain the expression of f = u + iv in terms of z = x + iy
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT