Final Exam Prep - Computer Programming - Tynes

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

1/44

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.

45 Terms

1
New cards

Which of the following values can correctly be saved in a boolean?

true

2
New cards

In Java, what is the value of 3 + 7 * 4 + 2?

33

3
New cards

Which assignment is correct in Java?

double money = 12.0;

4
New cards

Which Java statement produces the following output?

w

xyz

System.out.println ("w\nxyz");

5
New cards

Assuming you have declared shoeSize to be a variable of type int, which of the following is a valid assignment statement in Java?

shoeSize = 9;

6
New cards

Which symbol represents the operator used to derive the remainder in division?

%

7
New cards

Which of the following arithmetic operations is calculated first in an arithmetic expression?

within the parentheses

8
New cards

Which of these identifiers does not follow standard Java naming conventions?

Which of these identifiers does not follow standard Java naming conventions?

9
New cards

What will the following code display in the output?

int num = 7, amt = 3;num *= 2;num++;amt = num;amt += num / 2;System.out.println("num is " + num + "; amt is " + amt);

num is 15; amt is 22

10
New cards

The concatenation operator (+) is used to:

Combine text and variable values.

11
New cards

Which class is imported when desiring user input?

Which class is imported when desiring user input?

12
New cards

Your source code includes this line: public class SayGoodbye

What must be the name of the source code file?

SayGoodbye.java

13
New cards

What does this error message indicate is the problem? java:15: error: ' ; ' expected

Line 15 in the source code is missing a semicolon (;).

14
New cards

Refer to the following code fragment:

double answer = 13 / 5;

System.out.println ("13 / 5 = " + answer);

The desired output is: 13 / 5 = 2.6

Which of the following replacements for the first line of code WILL NOT fix the problem?

double answer = (double) (13 / 5);

15
New cards

Given: int result = 13 - 3 * 7 / 4 % 3;

What value is stored in result?

11

16
New cards

What is the output for the following code?

System.out.println("LM");System.out.print(245);System.out.println("CB");System.out.print(789);

LM

245CB

789

17
New cards

After execution of the following line of code, what will be the value of num3 ?

double num3 = 15 / 3;

5.0

18
New cards

Which line of code has an error that will be caught by the compiler?

String str = Sea World;

19
New cards

Which of the following could be used to instantiate a new Studentobject called sam?

Student sam = new Student ( );

20
New cards

Given: String school = "Xavier Prep";

What is the return value of school.length( )?

11

21
New cards

Given: String school = "Xavier Prep";

What is the return value of school.indexOf ("e")?

Given: String school = "Xavier Prep";

What is the return value of school.indexOf ("e")?

22
New cards

String school = "Centennial";String mascot = "Coyotes";

What is the return value of school.substring (mascot.indexOf ("y"), mascot.length())?

ntenn

23
New cards

What is the output?

public static int calculate(int a, int b){int num1 = a - 4;int num2 = b - 8;int num3 = num1 * num2;return num3;}public static void main(String[] args){int amt = 7, num = 10;int x = calculate(amt, num);System.out.println(amt + " fries");System.out.println(x + " shakes");}

7 fries

6 shakes

24
New cards

Given the following method header: public static void costOrder (int a)

Which of the following statements about the costOrder method is accurate?

It has no return value.

25
New cards

Assume that a and b are integers. Given: ! (a <= b) && (a * b > 0)

The given boolean expression will always evaluate to true given that . . .

a > b and b > 0

26
New cards

Which of these conditions will evaluate to true if string1 is "Circle"and string2 is "circle"?

if (string1.equalsIgnoreCase(string2))

27
New cards

Which of the following are logical operators?

AND, NOT, OR

28
New cards

In the program below, what term or expression is missing?

if (x == y)

{

System.out.println ("x and y are equal.");

}

else if (x > y)

{

System.out.println ("x is greater than y.");

}

{

System.out.println ("x is less than y.");

}

else (x

29
New cards

Which of these expressions is a valid way to compare the characters in string1 and string2?

(string1.equals (string2))

30
New cards

What value of x would make this boolean expression evaluate to false?

(x < 10) && (x != 5)

Any value greater than or equal to 10

31
New cards

What is the output of the following code snippet?

double ticketPrice = 12.75;

if(ticketPrice > 15)

{

System.out.println("Too expensive!");

}

else if(ticketPrice > 10)

{

System.out.println("Typical");

}

else if(ticketPrice > 5)

{

System.out.println("Great deal!");

}

else

{

System.out.println("Must be a scam");

}

Typical

32
New cards

What is the output of this program?

int numTreeRings = 50;

System.out.println("How old is the tree?");

if(numTreeRings > 10)

{

System.out.println("Older than my pear tree");

}

if(numTreeRings > 40)

{

System.out.println("Older than my apple tree");

}

if(numTreeRings > 150)

{

System.out.println("Older than my pine tree");

}

How old is the tree?

Older than my pear tree

Older than my apple tree

33
New cards

What is the output of this code?

String firstName = "Karel";

String lastName = "The Dog";

if (firstName.length() > lastName.length())

{

System.out.println (firstName + " is longer than " + lastName);

}

else

{

System.out.println (lastName + " is longer than " + firstName);

}

The Dog is longer than Karel

34
New cards

Which for loop will properly print "hello" 10 times?

for (int i = 0; i < 10; i++)

{

System.out.println ("hello");

}

35
New cards

Given: String str = "cats";

Which of the following segments of code will produce the following output?

cats

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

{

System.out.println(str.substring (i, i + 1));

}

36
New cards

How many times will "Hello" be printed?

for(int x = 1; x <= 30; x++){for(int a = 1; a <= 7; a++){System.out.println("Hello");}}

210

37
New cards

Given that n and count are both of type int, which statement is true about the following code segments?

System.out.print("Enter an integer for n: ");

int n = scan.nextInt();

int count;

I. for (count = 1; count < n; count++)

System.out.println (count);

II. count = 1;

while (count <= n)

{

System.out.println (count);

count++

}

I and II produce the exact same output only when n = 0.

38
New cards

Which of the following logical statements is equivalent to the following: !(A && B)

Where A and B are boolean variables

!A || !B

39
New cards

Given: String school = "Xavier Prep";

What is the return value of school.substring(8)?

rep

40
New cards

A method is declared as: public static void showResults (double d, int i).

Which of the following is a correct method call?

showResults (12.2, 67);

41
New cards

Given the method header: public static int aMethod (double d)

What is the data type of the return value?

int

42
New cards

Given: String school = "Xavier Prep";

What is the return value of school.substring (1, 4)?

avi

43
New cards

What is printed as a result of executing the following statement?

System.out.println (7 + 8 + (7 +8) + "Hello" + 7 + 8 + (7 + 8) );

30Hello7815

44
New cards

A high school class places students in a course based on their average from a pervious course. Students that have an average 92 or above are placed in an honors level course. Students that have an average below 74 are placed in a remedial level course. All other students are placed in a regular level course. Which of the following statements correctly places the student based on their average?

I. if (average >= 92)

level = "honors";

if (average < 74)

level = "remedial";

else

level = regular;

II. if (average >= 92)

level = "honors";

else if (average >= 74)

level = "regular";

else

level = "remedial";

III. if (average >= 92)

level = "honors";

else if ( (average >= 74) && (average < 92) )

level = "regular";

else

level = "remedial";

II and III only

45
New cards

Consider the following code segment.

int amount = initValue;

if (amount >= 0)

if (amount <=10)

System.out.println ("**");

else

System.out.println("%%");

Which of the following declarations for variable initValue will result in the printing of %% ?

initValue = 5