java final practice exam

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

word_count is a legal identifier in java

true

2
New cards

k2 is a legal identifier in java

true

3
New cards

Krazy1 is a legal identifier in java

true

4
New cards

hot? is a legal identifier in java

false

5
New cards

2ndPlaceWinnder is a legal identifier in java

true

6
New cards

2beOrNot2Be is a legal identifier in java

true

7
New cards

cous-cous is a legal identifier in java

false

8
New cards

its legal to have an integer variable named x and another integer variable named X in the same program

true

9
New cards
<p>what is the result of: </p>

what is the result of:

compiler error: can’t find symbol z

10
New cards

the most important job of the java compiler is to

to translate high-level languages (readable to humans) into lower-level languages (readable to computers)

11
New cards

what is the type of the expression ‘1’?

character

12
New cards

what is the type of the expression 23.2?

double

13
New cards

what is the type of the expression 32 + 2

integer

14
New cards

what is the type of the expression “32” + 2

string

15
New cards

what is the result of the expression 52482/24478198

0

16
New cards

what is the result of the expression: (true || (3 == 2))

true

17
New cards

what is the result of the expression: (!(4 < 2) && 3 < 10)

true

18
New cards

what is the result of the expression 2/5 ! = 2/5.0

false

19
New cards

what is the result of the expression !((true || 3 < 2 && !(false || true))

true

20
New cards

what is the result of the expression 18 % 5 × 10 + 3 × 4 / 2

36

21
New cards

what is the result of the expression: 2 % 5 × 4 + 3 × 5/2

15

22
New cards

what is the result of the expression 0 * (1264 + 2835) - 1.0

-1.0

23
New cards

what is the result of the expression 5+3%6/2+8×5/3

19

24
New cards

what is the result of the expression 3 > 3%5 + 2 || 5 < 7 && 1 < 2

true

25
New cards

what is the result of the expression 3 > 3 % 5 + 2 && 5 < 7 && 1 > 2 % 2

false

26
New cards

what is the result of the expression 2+1+”.”+(3/4)+3×4

3.012

27
New cards

what is the result of the expression “1”+5/2+3%4×5+(6+7)

121513

28
New cards

what is the result of the expression: “ascend”.charAt(1) + “acknowledge”.substring(3,6)

snow

29
New cards

turn into a java expression the statement “x is a multiple of y”

(x % y == 0)

30
New cards

write an if/else statement that prints “in the black” if revenue is the same or higher than expenses, otherwise print out “in the red”

if (revenue >= expenses) {
System.out.print(“in the black”);
} else {
System.out.print(“in the red”);
}

31
New cards

what is the output of the following code:
for (int i = 0; i < 10; i++) {
if (i % 3 == 1) {

System.out.print(i);
}
{

1 4 7

32
New cards

what is the output of this code:

for (int i = 0; i < 3; i++) {
for (int j = 0; j <= i; j++) {

System.out.print(i + j);

System.out.print(“ “);

}
System.out.print();

}

0
1 2
2 3 4

33
New cards

what is the output of this code?
public class Presidents {

public static void main(String args[]) {

int x = 10, y = 20, z = 30;
if (x<y) {

System.out.print(“Washington”);

} else if ((x+y) % 2 == 0) {

System.out.print(“Adams”);

} else if (z-2 < y+1) {

System.out.print(“Jefferson”);

} else {

System.out.print(“Madison”);

}

}

}

Washington

34
New cards

public class Presidents {

public static void main(String args[]) {

int x = 10, y = 20, z=30;

if (x<y) {

System.out.print(“Washington”);

} if ((x + y) % 2 == 0) {

System.out.print(“Adams”);

} else if (z-2 < y+1) {

System.out.print(“Jefferson”);

} else {

System.out.print(“Madison”);

}
}
}

Washington

Adams

35
New cards

what is the output of this code??
public static void main(String args[]) {

int x = 10, y = 20, z = 30;
if (x<y) {

System.out.print(“Washington”);

} else if ((x+y) % 2 == 0) {

if (z >= 30 || z <= 30) {

System.out.print(“(not Quincy) “);

}

System.out.print(“Adams”);

} else if (z-2 < y+1) {

System.out.print(“Jefferson”);

} else {

System.out.print(“Madison”);

}

}

Washington

36
New cards

what is the output of this code?
public static void main(String args[]) {

int x = 10, y = 20, z = 30;
if (x<y) {

System.out.print(“Washington”);

} if ((x+y) % 2 == 0) {

System.out.print(“Adams”);

} else if (z-2 < y+1) {

System.out.print(“Jefferson”);

} else {

if (x == 10) {

System.out.print(“Madison”);

} else {

System.out.print(“Monroe”);

}

}

}

Washington
Adams

37
New cards

what is the value of a, b, and c when the following code finishes?

int a = 5, b = 3 c =2;

if (c < a) {

c -= a;

} else if (b < a) {

b -= a';

}

if (a + b > c) {

a += 10;

} else {

b+= 10;

}

a = 15

b = 3

c = -3

38
New cards

what is the value of a, b, and c when the following code finishes?

int a = 1, b = 2, c = 3;

if (a *2 < b) {

a*=3;

c-=b;

}

if (b < a) {

b++;

} else {

a—;

c++;

}

a = 0

b = 2

c = 4

39
New cards

what is printed by the following?:

for (int i =1; i<4; i++) {

for (char c = ‘a’; c <= ‘c’; c++) {

if (i %2 == 0) {

i++;

System.out.print(i + “ “ + c)';

} else {

c++;

System.out.print(c + “ “ + i);

}

}

}

b 1

d 1

3 a

c 3

40
New cards

what is printed by the following?

String s1 = “bob”;

String s2 = “lob”;

String s3 = “law”;

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

if (i %2 == 0) {

s1 +=s2;

} else {

s2 = s1 + s3;

}

}

System.out.print(s1);

boblobbobloblaw

41
New cards

is there a compiler error in this code? if so, what is it? if not, whats printed?

public class WhatsPrinted1 {

public static void func(int x) {

x++;

}

public static void main(String args[]) {

int y = 10;

func(y);

System.out.print(y);

}

}

no error, 10

42
New cards

is there a compiler error in this code? if so what is it? if not, whats printed
public class WhatsPrinted1 {

public static void func(int x) {

x++;

System.out.print(x);

}

public static void main(String args[]) {

int y = 10;

func(y);

}

}

no error, 11 is printed

43
New cards

is there a compiler error in this code? if so, what is it if not, whats printed?

public static WhatsPrinted {

public static void func(int x, int, y, int z) {

x++;

y += z %2;

z *= 2;

}

public static void main (String args[]) {

int x = 10, y = 20, z = 30;

func(y, z, x);

System.out.print(x);

}

}

no error

10 is printed because only x is printed not the function result

44
New cards

is there a compiler error in this code? if so, what is it? if not whats printed?

public class WhatsPrinted4 {

public static void func(int x, int y, int z) {

x++;

y += z%2;

z *= 2;

System.out.print(z);

}

public static void main(String args[]) {

int x = 10, y = 20, z = 30;

func(y, z, x);

}

}

no error, 20 is printed

45
New cards

is there a compiler error in this code? if so, what is it? if not, whats printed?

public class WhatsPrinted {

public static int func(int x) {

x *= 2;

return x;

}

public static void main(String args[]) {

int x = 10;

func(x);

System.out.print(x);

}
}

no error, 10 because it did not print the function result

46
New cards

is there a compiler error in this code? if so what is it? if not what’s printed?

public class WhatsPrinted {

public static int func(int x) {

x *= 2;

return x;

}

public static void main(String args[]) {

int x = 10;

x = func(x);

System.out.print(x);

}

}

no error, 20

47
New cards

is there a compiler error in this code? if so, what is it? if not, what’s printed?

public class WhatsPrinted {

public static void func(String base, String prefix, String suffix) {

base = prefix + base + suffix;

}

public static void main(String args[]) {

String r = “ject”;

String p = “con'“;

String s = “ure”;

func(r, p, s);

System.out.print(r );

}

}

no error, “ject”

48
New cards

is there a compiler error in this code? if so, what is it? if not, what’s printed?

public class WhatsPrinted {

public static void func(String base, String prefix, String suffix) {

base = prefix + base + suffix;

return base;

}

public static void main(String args[]) {

String r = “ject”;

String p = “con'“;

String s = “ure”;

func(r, p, s);

System.out.print(r );

}

}

no error, “ject”

49
New cards

is there a compiler error in this code? if so, what is it? if not, what’s printed?

public class WhatsPrinted {

public static void func(String base, String prefix, String suffix) {

base = prefix + base + suffix;

return base;

}

public static void main(String args[]) {

String r = “ject”;

String p = “con'“;

String s = “ure”;

r = func(r, p, s);

System.out.print(r );

}

}

no error, “conjecture“

50
New cards

is there a compiler error in this code? if so, what is it? if not, what’s printed?

public class WhatPrinted {

public static void f1() {

System.out.print(“a”);

}

public static void f2() {

f1();

System.out.print(“b”);

}

public static void f3() {

f2();

f1();

System.out.print(“c”);

}

public static void main(String args[]) {

f3();

System.out.print();

}

}

no error, abac