Lec 4 Characters and Strings Flashcards

1
Q

char letter = ‘A’
What type of char is letter?

A

ASCII

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

char numChar = ‘4’
what type of char is this?

A

ASCII

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

char letter = ‘\u0041’
what type of char is letter?

A

unicode char

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or False: A java character is stored in 2 bytes

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the output of System.out.println(“smith\exam1\test.txt”)? Pretend there are double \’s

A

smith\exam1\test.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or false: An int variable can hold ‘x’

A

True, but ‘x’ = 120

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or false: An int variable can hold ‘120’

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does Character.isDigit(ch) return?

A

Boolean
Whether or not the input is a character that holds a digit, like ‘1’ returns true, but ‘a’ returns false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does Character.isLetter(ch) return?

A

Boolean
Whether or not if the character is a letter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does Character.isLetterOrDigit(ch) return?

A

Boolean
Whether or not the character is a letter or digit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does Character.isLowerCase(ch) return?

A

Whether the character is an uppercase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does Character.toLowerCase(ch) return?

A

the lowercase character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does str.toUpperCase() return?

A

the uppercase version of str

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does str.charAt(index) return?

A

the char at the index of str

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does str.concat(“s1”) return?

A

the concatenated version of str and “s1”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what does str.toUpperCase() return?

A

the all capitalized version of str

17
Q

What does trim() return?

A

the string without any whitespaces on both sides

18
Q

What is the difference between instance and static methods?

A

instance methods can only be invoked from a specific string method while a static method is a non-instance method and can be invoked without using an object

19
Q

What is the syntax to invoke a static method?

A

Classname.methodname(args)

20
Q

True or False: Character.toUpperCase(c) is a static method

A

False. The method is called on an obj and is therefore an instance method

21
Q

True of False: Math.sin(2) is an instance method

A

False. All Math methods are static methods and don’t use an obj

22
Q

Unicode for “A” is 65. What does “A” + 1 equal?

23
Q

Unicode for ‘A’ is 65. What does ‘A’ + 1 equal?

24
Q

How to uppercase all characters in “java”?

A

“java”.toUpperCase()

25
What is the return value of "SELECT".substring(0,5)?
"SELEC"
26
What is the job of Integer.parseInt(s)?
parses a string s into an int value
27
How to convert a string into an int?
Integer.parseIt(intString)
28
How to convert number to string?
String s = number + ""
29
In terms of specifiers, what is %b used to denote?
Boolean value in printf() System.out.printf("boolean here: %b", booleanValue)
30
Will System.out.printf("count is and amount is: ", count, amount) print the numbers?
No, as there is no specifiers like %d for decimal numbers and %f for floating point numbers specified
31
What does input.next() do?
listen for next console input of one word
32
What does input.nextLine() do?
Listen for input from the console for the entire line
33
What does indexOf(ch) return?
returns the index of the first occurrence of ch in the string and returns -1 if not matched
34
What does indexOf(ch, fromIndex) return?
returns the index of the first occurrence of ch after fromIndex in the string and returns -1 if not matched
35
What does indexOf(s) return?
returns the index of the first occurrence of string s in this string and returns -1 if not matched
36
What does indexOf(s, fromIndex) return?
returns the index of the first occurrence of a string s in the string after fromIndex and returns -1 if not matched
37
What does lastIndexOf(ch) return? Very similar to lastIndexOf(s)
returns the last index of the last occurrence of ch or s in this string and returns -1 of not matched
38
What does lastIndexOf(ch, fromIndex) return? Very similar to lastIndexOf(s, fromIndex)
returns the index of the last occurrence of ch or s before fromIndex in this string and returns -1 if not matched