Programming and Problem Solving with Java

(やまだぃちぅ) #1
145

System.out.println(“Price is “+ price + “Cost is “+ cost);
System.out.println(“Grade “+ ch + “ costs “);
System.out.println(cost);
}
}

7.Translate the following Java code into algebraic notation. (All variables are
doublevariables.)
y = -b + Math.sqrt(b b – 4.0 a * c);


8.Given the code fragment:


int i;
int j;
doublez;

i = 4 ;
j = 17 ;
z = 2.6;
determine the value of each of the following expressions. If the result is a float-
ing-point value, include a decimal point in your answer.
a.i / (double)j
b.1.0/ i + 2
c. z * j
d.i + j % i
e.( 1 / 2 ) * i
f. 2 * i + j – i
g.j / 2
h. 2 * 3 – 1 % 3
i. i % j / i
j. (int)(z + 0.5)

9.Evaluate the following expressions. If the result is a floating-point number,
include a decimal point in your answer.
a.Math.abs(–9.1)
b.Math.sqrt(49.0)
c. 3 (int)7.8+ 3
d.Math.pow(4.0, 2.0)
e.Math.sqrt((double)( 3
3 + 4 * 4 ))
f. Math.sqrt(Math.abs(–4.0) + Math.sqrt(25.0))

Free download pdf