144
3.Compute the value of each legal expression. Indicate whether the value is an in-
teger or a floating-point value. If the expression is not legal, explain why.
Integer Floating Point
a.10.0/ 3.0+ 5 * 2 ______ _______
b. 10 % 3 + 5 % 2 ______ _______
c. 10 / 3 + 5 / 2 ______ _______
d.12.5+ (2.5/ (6.2/ 3.1)) ______ _______
e.– 4 * (– 5 + 6 ) ______ _______
f. 13 % 5 / 3 ______ _______
g.(10.0/ 3.0% 2 ) / 3 ______ _______
4.What value is stored into the intvariable resultin each of the following?
a.result = 15 % 4 ;
b.result = 7 / 3 + 2 ;
c. result = 2 + 7 * 5 ;
d.result = 45 / 8 * 4 + 2 ;
e.result = 17 + ( 21 % 6 ) * 2 ;
f. result = (int)(4.5+ 2.6* 0.5);
5.If aand bare intvariables with a= 5 and b= 2, what output does each of the fol-
lowing statements produce?
a.System.out.println(“a = “+ a + “b = “+ b);
b.System.out.println(“Sum:”+ a + b);
c. System.out.println(“Sum: “+ a + b);
d.System.out.println(a / b + “ feet”);
6.What does the following application print?
public classExamPrep
{
public static voidmain(String[] args)
{
final intLBS = 10 ;
int price;
int cost;
charch;
price = 30 ;
cost = price * LBS;
ch = 'A’;
System.out.println(“Cost is “);
System.out.println(cost);