Java

TOPIC 51 – TEST REVIEW

 

DETAILS & REVIEW


 

DETAILS


Your test will be fully written.  You will not have a computer.

 

Minor programming errors will not count against you.

 

The test covers everything in the unit.

 

 

REVIEW

 

QUESTION 1 – DEFINITIONS

You should be comfortable with the following terms:

 

          String

          Immutable class

          Empty string

 

QUESTION 2 – STRING METHODS

What do the following methods do?

 

  1. equals(String str)
  2. length()
  3. toLowerCase()
  4. toUpperCase()
  5. indexOf(String str)
  6. substring(int a, int b)
  7. substring(int a)
  8. contains(String str)

 

QUESTION 3 – SHORT ANSWER QUESTIONS

Answer the following questions:

 

a)    Can a String object be changed?

 

b)    Is the String class mutable or immutable?

 

c)     The first index in a String is _____.

 

d)    Is the equals() method case sensitive?

e)    hello”.substring(0,2) returns _____.

f)      hello”.substring(2) returns _____.

g)    When the + symbol is used between strings, it is called _____ _____.


QUESTION 4 – CODING QUESTIONS

 

a) Write the program that gets a String from the user and outputs it such that the first letter is capitalized and the rest of the word is in lower case.

b) Write a program that gets a String from the user and outputs it one letter at a time to the screen.

c) Alter your code from the previous question so that the String is outputted one letter at a time but backwards.

d) Write a program that has a String that contains a sentence such as “Well hello there my friend”.  The program outputs how many words are in the sentence.

Hint: You can simply count the spaces.

 

You can now tell people that you know String Theory!

J