Quiz 6
Wednesday
With a piece of paper, write down your name and answers to the following questions.
What is the name of the character that separates tokens in a string?
- Separator
- Tokenizer
- Delimiter
- Terminator
The
startsWithandendsWithmethods are members of which class?CharCharacterStringBuilderString
Which
StringTokenizermethod returnstrueif there are more tokens to be extracted from a string?moreTokenstokensLeftgetTokenhasMoreTokens
Is the following statement correct, and why?
Character testing methods in the
Characterclass, such asisLetter, accept strings as arguments and test each character in the string.Answer: False, character testing methods in the
Characterclass, such asisLetter, acceptchartype data as argumentsFind and correct the error in the following program.
public class Program { public static void main(final String[] args) { StringBuilder builder = "CSCI 2912"; builder.append("Hawaii Pacific University"); } }Correction:
public class Program { public static void main(final String[] args) { StringBuilder builder = new StringBuilder("CSCI 2912"); builder.append("Hawaii Pacific University"); } }Or:
public class Program { public static void main(final String[] args) { StringBuilder builder = new StringBuilder(); builder.append("CSCI 2912"); builder.append("Hawaii Pacific University"); } }
Student Performance and Statistics
A histogram of student performance on percentage grades for Quiz 6 on Wednesday.
A table showing the average performance for each question in Quiz 6 on Wednesday.
Friday
With a piece of paper, write down your name and answers to the following questions.
What is one of the methods that are common to both the
Stringand theStringBuilderclasses?lengthinsertappenddelete
The
isLetter,isDigit, andisUpperCasemethods are members of which class?CharCharacterStringBuilderString
These
staticfinalvariables are members of the numeric wrapper classes, and they hold the minimum and maximum values for a particular data type. What are they?MIN_VALUEandMAX_VALUEMINandMAXMINIMUMandMAXIMUMLOWESTandHIGHEST
Is the following statement correct, and why?
To use a numeric wrapper class, such as
Character, you need to write the correspondingimportstatement.Answer: False, first, the
Characterwrapper class is not numeric; second, wrapper classes are part of thejava.langpackage, so there is no need for animportstatement.Find and correct the error in the following program.
import java.util.StringTokenizer; public class Program { public static void main(final String[] args) { // Tokenize a string that is delimited with semicolons. This // string contains three tokens: "one", "two", and "three". StringTokenizer tokenizer = new StringTokenizer("one;two;three"); while (tokenizer.hasMoreTokens()) System.out.println(tokenizer.nextToken()); } }Correction:
import java.util.StringTokenizer; public class Program { public static void main(final String[] args) { // Tokenize a string that is delimited with semicolons. This // string contains three tokens: "one", "two", and "three". StringTokenizer tokenizer = new StringTokenizer("one;two;three", ";"); while (tokenizer.hasMoreTokens()) System.out.println(tokenizer.nextToken()); } }Or:
import java.util.StringTokenizer; public class Program { public static void main(final String[] args) { // Tokenize a string that is delimited with spaces. This // string contains three tokens: "one", "two", and "three". StringTokenizer tokenizer = new StringTokenizer("one two three"); while (tokenizer.hasMoreTokens()) System.out.println(tokenizer.nextToken()); } }
Student Performance and Statistics
A histogram of student performance on percentage grades for Quiz 6 on Friday.
A table showing the average performance for each question in Quiz 6 on Friday.