144k views
3 votes
B) Given a = 2, b = 3 and c = 5, evaluate the following logica i. (a b) && (c != 5) c) Declare and Initialize the following using the appropriate.

i. Soccer scores
ii. Area of a triangle
iii. 365 (N.B. no. of days in a year)
c. Assume x = 4, y = 7, and z= 2. What value will be store each of the following statements?
i. result = x/y;
ii. result = y* 2;
iii. result = y + z;
d. What is the output for the expression below?
x = 6
y = ++x
PRINT x
PRINT y ​

User Karakuri
by
8.8k points

1 Answer

5 votes

b)

i. (a b) && (c != 5) evaluates to false because (2 < 3) is true, but (5 != 5) is false.

c)

i. Soccer scores can be declared and initialized as an array of integers, like this: int[] scores = {2, 1, 4, 3, 0};

ii. The area of a triangle can be calculated using the formula: area = (base * height) / 2. To declare and initialize the area of a triangle, we need to know the base and height. For example, if the base is 5 and the height is 3, we can write: double area = (5 * 3) / 2;

iii. The number of days in a year is a constant value that can be declared and initialized using the keyword "final": final int DAYS_IN_YEAR = 365;

c)

i. result = x/y; evaluates to 0 because x = 4 and y = 7, so 4/7 is less than 1.

ii. result = y* 2; evaluates to 14 because y = 7, so 7 * 2 = 14.

iii. result = y + z; evaluates to 9 because y = 7 and z = 2, so 7 + 2 = 9.

d)

The output for the expression below is:

x = 6

y = ++x

PRINT x // output is 7

PRINT y // output is 7

The expression "++x" increments the value of x by 1 before assigning it to y, so y is equal to 7. When we print x, the output is also 7 because x was incremented by 1.

User Joseph Wu
by
8.6k points