RU beehive logo ITEC dept promo banner
ITEC 120
2009spring
ibarland
nokie
jmdymacek

homeinfolectslabsexamshws
textbooktutor/PIsjava.lang docsjava.util docs

lab02a
calling String methods

We saw in lecture that to use a variable, we

  1. Declare the variable (For example: double height;)
  2. initialize the variable (for example: height = 9.0;

Another example: here is how we declare a variable named bestSchool which stores the String value "Radford U.":

  String bestSchool;
  bestSchool = "Radford U.";
Once we do this, we can ask questions of that String — for example, we can ask for the character it has at index 2:
  bestSchool.charAt(2)
(How did we know that a method named “charAt” existed? We just had the teacher tell us, and s/he just looked it up in a reference book. It's relatively shallow knowledge.)

Practice task: In BlueJ's code pad:

Together, with the lab instructor: In the code pad, we'll ask Strings a different method. try calling a method named “replace”. whose answer is like the original string, except with one set of letters replaced with another.

Today's Task

P2.9 from the textbook (substituting letters in a String).

homeinfolectslabsexamshws
textbooktutor/PIsjava.lang docsjava.util docs


©2009, Ian Barland, Radford University
Last modified 2009.Feb.04 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme