Primitive Data Types

Practice Questions

Computer Science › Primitive Data Types

Page 1 of 12
10 of 114
1

Which of the following Boolean expression evalutes to True?

I. False && False && False && True && False

II. (False && False) || (True || False) || (False && (True || False))

III. (True && False) && (True || False || (True && True))

IV. !(True && True && False)

V. False || False || False || True || False

2

Which is true?

a = 4

b = 2

c = 5

d = 6

a) a = c - d

b) a = b - d

c) a = d - b

d) a = c * d

3

boolean x;
int y;
x = false;
y = 10;
x = !(y < 10 || y > 10);

System.out.println ( x );

What is printed?

4

Consider the following code:

int\[\] a = {8,4,1,5,1,5,6,2,4};

int b = 1;

boolean\[\] vals = new boolean\[a.length\];

for(int i = 0; i < a.length; i++) {

vals\[i\] = (a\[i\] - 1 > 4);

}

for(int i = 0; i < vals.length; i++) {

String s = "Duns Scotus";

if(!vals\[i\]) {

s = "Mithrandir";

}

System.out.println(s);

}

What is the output for the code above?

5

Consider the following code:

int\[\] a = {8,4,1,5,1,5,6,2,4};

int b = 1;

boolean\[\] vals = new boolean\[a.length\];

for(int i = 0; i < a.length; i++) {

vals\[i\] = (a\[i\] - 1 > 4);

}

for(int i = 0; i < vals.length; i++) {

String s = "Duns Scotus";

if(!vals\[i\]) {

s = "Mithrandir";

}

System.out.println(s);

}

What is the output for the code above?

6

boolean x;
int y;
x = false;
y = 10;
x = !(y < 10 || y > 10);

System.out.println ( x );

What is printed?

7

Which of the following Boolean expression evalutes to True?

I. False && False && False && True && False

II. (False && False) || (True || False) || (False && (True || False))

III. (True && False) && (True || False || (True && True))

IV. !(True && True && False)

V. False || False || False || True || False

8

Which is true?

a = 4

b = 2

c = 5

d = 6

a) a = c - d

b) a = b - d

c) a = d - b

d) a = c * d

9

int currentYear = 2016;

bool leapYear;

``

if (currentYear % 4 == 0) {

leapYear = true;

} else {

leapYear = false;

}

``

febDays = leapYear ? 28 : 29

Based on the code above, what value will febDays have?

10

int currentYear = 2016;

bool leapYear;

``

if (currentYear % 4 == 0) {

leapYear = true;

} else {

leapYear = false;

}

``

febDays = leapYear ? 28 : 29

Based on the code above, what value will febDays have?

Page 1 of 12
Return to subject