java programming chapter 4: ~advanced~ strings

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

string literal

"Start Game"

less memory, security BUT every time you edit a string you have to make a new string

advantages/disadvantages of immutable data types

can edit after it has been created BUT takes up more memory

advantages/disadvantages of mutable data types

coossmsmimic

determine the output when the mystery2 method is called. *mystery2("cosmic");* public static void mystery2(String s) { for(int i = 1; i <= s.length(); i++) { System.out.print(s.substring(i/2, i)); } }

concatenation = combining *strings* together append = add onto existing *string builder*

difference between concatenation and append

index

each character in a string is assigned an ________ number

s.substring(x, y)

returns a substring of s, starting at index x to index y exclusive - does not include y as part of the substring

s.charAt(x)

returns the *character* at index x (in this case, x must be an integer)

s.indexOf(x)

returns the *index number* of x (x can be character or string); if x is not in s, return -1

memory address

001

memory address

the _________ is the location in the computer's memory where the string is stored

memory addresses

what does the following code compare? *a == d → false*

literals

what does the following code compare? *a.equals(d) → true*

reference tyoe

what type of variable is the following? String

primitive type

what type of variables are the following? int, double, char, boolean

false

Use the table below to select true or false *a == d* MA: 000 Identifier: a Literal: "Hello" MA: 001 Identifier: b Literal: "World" MA: 010 Identifier: c Literal: "Hello World" MA: 011 Identifier: d Literal: "Hello"

true

Use the table below to select true or false *a.equals(d)* MA: 000 Identifier: a Literal: "Hello" MA: 001 Identifier: b Literal: "World" MA: 010 Identifier: c Literal: "Hello World" MA: 011 Identifier: d Literal: "Hello"

Wor

Using the table below, what is returned with the following code? *b.substring(0,3)* MA: 000 Identifier: a Literal: "Hello" MA: 001 Identifier: b Literal: "World" MA: 010 Identifier: c Literal: "Hello World" MA: 011 Identifier: d Literal: "Hello"

o

Using the table below, what is returned with the following code? *c.charAt(4)* MA: 000 Identifier: a Literal: "Hello" MA: 001 Identifier: b Literal: "World" MA: 010 Identifier: c Literal: "Hello World" MA: 011 Identifier: d Literal: "Hello"

10

Using the table below, what is returned with the following code? *c.indexOf('d')* MA: 000 Identifier: a Literal: "Hello" MA: 001 Identifier: b Literal: "World" MA: 010 Identifier: c Literal: "Hello World" MA: 011 Identifier: d Literal: "Hello"

11

Using the table below, what is returned with the following code? *c.length()* MA: 000 Identifier: a Literal: "Hello" MA: 001 Identifier: b Literal: "World" MA: 010 Identifier: c Literal: "Hello World" MA: 011 Identifier: d Literal: "Hello"

World

Using the table below, what is returned with the following code? *c.substring(d.length(), c.length())* MA: 000 Identifier: a Literal: "Hello" MA: 001 Identifier: b Literal: "World" MA: 010 Identifier: c Literal: "Hello World" MA: 011 Identifier: d Literal: "Hello"

append

__________ means to add onto the existing item

concatentation

___________ means to combine strings together to make a new string

primitive

a __________ type is a variable that holds a value

reference

a ____________ type is a variable that holds a memory address

mutable

a data type that is _______ CAN be changed once it is created

immutable

a data type that is _________ CANNOT be changed once it is created

21645703

determine the output when the mystery1 method is called. *mystery1("sunlight", "hustling");* public static void mystery1(String a, String b) { for(int i = 0; i < a.length(); i++) { System.out.print(b.indexOf(a.charAt(i))); } }

3201

determine the output when the mystery1 method is called. *mystery1("west", "stew");* public static void mystery1(String a, String b) { for(int i = 0; i < a.length(); i++) { System.out.print(b.indexOf(a.charAt(i))); } }

apprriril

determine the output when the mystery2 method is called. *mystery2("april");* public static void mystery2(String s) { for(int i = 1; i <= s.length(); i++) { System.out.print(s.substring(i/2, i)); } }

s.length()

returns *number of characters* in s note: white spaces count as characters for string "hi ho", the number returned would be 5

pool

the string ________ is a list of all the strings used in a program, created when compiling a file

literal

the string ________ is the sequence of characters inside the double quotation marks


Ensembles d'études connexes

Chapter 9: Sleep and Biological Rhythms

View Set

Chapter 9 - Teaching and Counseling

View Set

Chapter 30 Formation and Internal Relations of General Partnerships

View Set