Int

Practice Questions

Computer Science › Int

Page 1 of 2
10 of 11
1

Consider the following code:

int i = 55, j = 3;

System.out.println((i / j + 3) / 5);

What is the output for the code above?

2

Consider the code below:

int val = 205;

for(int i = 0; i < 5; i++) {

val /= 2;

}

At the end of its execution, what is the value of the variable val in the code above?

3

Consider the following code:

int i = 100;

double d = 4.55, d2 = 3.75;

int j = (int)(d * 100 + d2);

What is the value of j at the end of the code's execution?

4

Consider the following code:

int i = 3;

for(int j = 5; j > 0; j--) {

i += i;

}

What will be the value of i at the end of this loop's iteration?

5

How do we set a method to return an Int in Swift(iOS)?

6

int x = 10;

int y = 4;

``

int z = x / y;

What is the value of z?

7

Which of the following gurantees that your division does not lose its decimal portion?

8

Which of the following variable assignments is NOT a valid assignment statement?

a. 15 = x - 15;

b. num = x * y;

c. x = y + 15

d. x + y = 15

9

Suppose you are given the following lines of code:

Integer a = new Integer(10);

Integer b = new Integer(4);

Which of the following lines will not generate an error?

I. if (a.intValue() == b.intValue())

II if ((a.toString()).equals(b.toString()))

III if ((a.intValue()).equals(b.intValue()))

10

Refer to the following line of code:

double d = -4.73;

Which of the following correctly rounds d to the nearest integer?

Page 1 of 2
Return to subject