E-Commerce Exercise

Only available on StudyMode
  • Download(s) : 730
  • Published : February 20, 2011
Open Document
Text Preview
Characters, Strings, and the StringBuffer

Quick Quiz 1

1. As an object, a String variable name is not a simple data type. It is a(n) ____; that is, a variable that holds a memory address.

1. The ____ method of the Character class returns true if the argument is a digit (0–9) and false otherwise.

2. What is the value of result in the following program code? char aChar = 'C';
Boolean result = Character.isWhitespace(aChar);

Quick Quiz 2

1. True or False: The class String is defined in java.lang.String, which is automatically imported into every program you write.

2. Strings and other objects that can’t be changed are known as ____.

3. The String class ____ method evaluates the contents of two String objects to determine if they are equivalent.

4. The ____ method requires an integer argument that indicates the position of the character that the method returns.

Quick Quiz 3

1. To convert a String to an integer, you use the Integer class, which is part of ____ and is automatically imported into programs you write.

2. A method of the Double class is the ____ method, which takes a String argument and returns its double value.

3. True or False: You can change the length of a String in a StringBuffer object with the setLength() method.

Class Discussion Topics

1. Why do you think Java provides primitive data types AND wrapper classes for them? Why not just one or the other?

2. Under what circumstances would you choose to use the String class? When would you use StringBuffer?

Additional Projects

1. Create a program that prompts the user to enter two Strings. Then display the Strings in alphabetical order. If the two Strings are equal, display a message that they are equal rather than printing them in alphabetical order.

2. In addition to the methods covered in this chapter, Java provides a number of classes used to convert and format...
tracking img