Java String and Control Flow Concepts, Exams of Biology

A wide range of java programming concepts, including string manipulation, control flow statements, and various programming constructs. It provides explanations and examples for topics such as string concatenation, string methods, conditional statements, loops, and more. Structured in a question-and-answer format, making it a valuable resource for students and developers looking to deepen their understanding of fundamental java programming principles. The content covers a broad range of topics, from basic string operations to advanced control flow techniques, making it a comprehensive reference for anyone studying or working with java.

Typology: Exams

2023/2024

Available from 08/25/2024

Lectmark
Lectmark 🇺🇸

3.9

(7)

5.1K documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
rephactor questions - weeks 3-6
which operator is used to perform string concatenation in Java - correct answer +
if a String variable called greeting contains the characters "hello" what does the following expression
do:
greeting.toUpperCase() - correct answer returns a new string containing the characters "HELLO"
if a string variable called pioneer contains the characters "Grace Murray Hopper", what is the result
of the following expression:
pioneer.length() - correct answer 19
given the following declaration which expression would extract the substring "ledge"
String words = "Knowledge is power."; - correct answer words.substring(4, 9);
what output would be produced when the following is executed:
String state = "Mississippi";
System.out.println(state.replace("is", "was")); - correct answer Mwasswassippi
If a String variable called address contains the characters "123 Main Street", what is the result of the
following expression:
address.indexOf('3') - correct answer 2
which statement would produce the following output?
"Oom Pah Pah Oom Pah Pah," that's how it goes. - correct answer System.out.println("\"Oom Pah
Pah Oom Pah Pah,\" that's how it goes.");
which of the following literals is NOT valid:
a. '"'
b. "\"\n"
c. ""\n""
d. '\n' - correct answer c. ""\n""
pf3
pf4
pf5
pf8

Partial preview of the text

Download Java String and Control Flow Concepts and more Exams Biology in PDF only on Docsity!

rephactor questions - weeks 3-

which operator is used to perform string concatenation in Java - correct answer +

if a String variable called greeting contains the characters "hello" what does the following expression do:

greeting.toUpperCase() - correct answer returns a new string containing the characters "HELLO"

if a string variable called pioneer contains the characters "Grace Murray Hopper", what is the result of the following expression:

pioneer.length() - correct answer 19

given the following declaration which expression would extract the substring "ledge"

String words = "Knowledge is power."; - correct answer words.substring(4, 9);

what output would be produced when the following is executed: String state = "Mississippi";

System.out.println(state.replace("is", "was")); - correct answer Mwasswassippi

If a String variable called address contains the characters "123 Main Street", what is the result of the following expression:

address.indexOf('3') - correct answer 2

which statement would produce the following output?

"Oom Pah Pah Oom Pah Pah," that's how it goes. - correct answer System.out.println(""Oom Pah

Pah Oom Pah Pah," that's how it goes."); which of the following literals is NOT valid: a. '"' b. ""\n" c. ""\n""

d. '\n' - correct answer c. ""\n""

what is the output of the following statement:

System.out.println("He said "Avada Kedavra""); - correct answer He said "Avada Kedavra"

what is \t - correct answer a horizontal tab

what is \n - correct answer a newline character which sends the output to the next line

what do the characters in a Unicode escape sequence represent? - correct answer the hexadecimal

code for a particular Unicode character

a small character set containing primarily English characters and basic symbols - correct answer

ASCII

a way to represent non-ASCII Unicode characters in a program - correct answer Unicode escape

sequence

the technique of ordering characters based on a character set - correct answer lexicographic

ordering

the way characters are stored in memory - correct answer character encoding

characters that don't map to the fixed-width, 16-bit Unicode encoding - correct answer

supplementary characters

characters (like newline) that have no visual symbol - correct answer non-printable characters

the character set Java uses to represent characters - correct answer Unicode

A list of characters used by a programming language - correct answer character set

the String class is part of the java.__ package - correct answer lang

if (total > 8)

System.out.println("collywobbles"); - correct answer the word collywobbles is not printed and

processing continues what output is printed by the following code if it is executed when appetizer is 3 and entree is 12? if (appetizer > 1) if (entree < 7) System.out.println("ketchup"); else System.out.println("mustard"); else if (appetizer < 0) System.out.println("mayonnaise"); else

System.out.println("relish"); - correct answer mustard

the condition of an if statement must be a ____ expression - correct answer boolean

What is wrong with the following code: if (count > 5) if (sum < MAX) System.out.println("cattywampus"); else

System.out.println("snickersnee"); - correct answer the indentation does not properly reflect the

processing Of the options given, what values of the variables height, size, and width would cause the following code to set the variable weight to 100? if (height < size) { weight = 50; if (width < 20)

System.out.println("short"); } else { if (width > 100) weight = 100; System.out.println("tall"); } a. height = 15, size = 10, width = 110 b. height = 15, size = 25, width = 50 c. height = 20, size = 12, width = 90

d. height = 12, size = 20, width = 200 - correct answer a. height = 15, size = 10, width = 110

the result of a __ __ can be assigned to a boolean variable - correct answer relational operator

the ___ operators have a lower precedence than the ___ operators - correct answer relational;

arithmetic

the relational operators can/cannot be used to put String objects in alphabetical order - correct

answer cannot

the less than operator (<) can/cannot be used to compare floating-point values - correct answer

can

the not operator (!) requires ___ operand(s) - correct answer one

if A and B are both false, then A && B is ___ - correct answer false

if A is true and B is false, then A || B is ___ - correct answer true

the exclusive or operator (^) produces/does not produce results that are opposite to the regular or

operator (||) - correct answer does not produce

If the value of num is 7 and the value of max is 10 what is the value of num after the following statement is executed:

num = (max < num)? max : max - num; - correct answer 3

What does the following statement print:

System.out.println((count < 0)? "Invalid" : count); - correct answer the value of count, or "Invalid"

if count is negative

in the switch statement, the case values must be _____ - correct answer constants

in most cases, a switch statement relies on the ___ statement to terminate each case - correct

answer break

a while loop is based on a _____ condition - correct answer boolean

a special value used to indicate the end of the input is called - correct answer a sentinel value

the indexOf method of the String class returns a value of __ if the character is not found - correct

answer -

in the Palindrones program, the ___ ___ evaluates one string to see if it is a palindrome - correct

answer inner loop

the Java - ___ is a repetition statement, or loop, allowing you to execute a set of programming

statements multiple times - correct answer do-while statement

a value that is passed into a method when it is called - correct answer argument

defines the code that is executed when a method is called - correct answer method declaration

variables declared inside of a method body - correct answer local data

part of the method header that specifies the type of value the method produces - correct answer

return type

the statement used to return a value from a method - correct answer return statement

the name used to refer to a value passed into a method - correct answer formal parameter

the keyword used as the return type for a method that doesn't return a value - correct answer void