Download System.out.println(state.indexOf(“iss”))

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Intro to Programming
Name:
Exercises 12.01- 07 Date:
Period:
1.
Give an example of something that involves String Processing.
2.
Is String a primitive data type, or a class?
3.
All Java classes start with _________________________.
4.
String has many _______ that facilitate string manipulations.
5.
What is a String?
6.
The characters in a String include 4 things. List them.
7.
What is a string literal?
8.
Consider this statement: String city = “Dallas”;
What is the string variable and what is the string literal?
9.
Whenever the new keyword is used in Java, it means a new object is being constructed.
Is it possible to construct a new object in Java without using the new operator?
10.
Consider this statement: String city1 = “Dallas”;
Create 4 more String objects, city2, city3, city4, and city5, which will also store “Dallas”.
Each object needs to be created in a different manner. This counts as 4 questions.
11.
12.
13.
Intro to Programming Exercises 12.01-07
Page 1
14.
What is concatenation?
15.
When does the plus [ + ] operator perform concatenation?
16.
Assume firstName equals “John ” and lastName equals “Smith”.
Write a program statement that will concatenate the 2 variables into a fullName.
17.
What does the length method return?
18.
With arrays, length is a _______. With strings, length is a _______.
19.
Look at the output of program Java1203.java. If “Argentine” has 9 characters and “Tango” has 5
characters, how is it that “Argentine Tango” has 15 characters when 9 + 5 = 14?
20.
What are invisible characters called?
21.
You will note that not only do strings and arrays share the concept of length, they also share the concept
of indexes. You will also note that just like arrays, the first index is _______ and the last index is
______________.
22.
In some languages like C++, a string is an array of characters. Is this true in Java?
23.
What method accesses the character at the index of the method argument?
24.
Characters can be concatenated to the end of a String object using the _______ operator.
For questions 25 through 28 assume school is a String that stores “John Paul II”.
25.
What would be the output of this statement?
System.out.println(school.charAt(2));
26.
What would be the output of this statement?
System.out.println(school.charAt(5));
27.
What would be the output of this statement?
System.out.println(school.substring(0,4));
28.
Refer to the previous question. How would you change this command to make it display “Paul”?
Intro to Programming Exercises 12.01-07
Page 2
For questions 29 through 35 assume state is a String that stores “Mississippi123”.
29.
What would be the output of this statement?
System.out.println(state.indexOf(“iss”));
30.
What would be the output of this statement?
System.out.println(state.lastIndexOf(“iss”));
31.
What would be the output of this statement?
System.out.println(state.replace(‘s’,‘p’));
32.
Refer to the previous question.
How would you change this command to make it display “Massassappa123” ?
33.
What would be the output of this statement?
System.out.println(state.toUpperCase());
34.
What would be the output of this statement?
System.out.println(state.toLowerCase());
35.
Refer to the previous 4 questions. If all 4 commands were executed in sequence, what value will be stored
in state? (Careful: Trick Question)
36.
List 4 primitive data types.
37.
Which static method coverts simple data types to String objects?
38.
Refer to the previous question. Why is this method called a static method?
39.
Which methods will convert a String to an int?
40.
Which methods will convert a String to a double?
41.
The equality operator == is strictly reserved for the __________ data types.
42.
Refer to the previous question. What should be used instead of the == operator when comparing Strings?
Intro to Programming Exercises 12.01-07
Page 3
Questions 43 through 45 refer to this statement:
System.out.println(s1.compareTo(s2));
Both s1 and s2 are String objects.
43.
What does it means if this program statement displays a negative number?
44.
What does it means if this program statement displays a positive number?
45.
What does it means if this program statement displays 0?
Intro to Programming Exercises 12.01-07
Page 4