CPS 1 - Spring, 1998 - Ramm 1/30 #7
- Announce
- Finish Reading Chapter 2
- Office Hours for Chris and Eric moved to D328 LSRC
Chapt 2. Text Manipulation and Algorithm Design
- Example Doing Multiple Tallies
Tallies.java,
tallies.html
- Used Integers and Plus Operator
- All five integer operators:
-
+, -, *, /, %
- Operator Precedence
Strings and String Manipulation
- The
String Class
- Declaration:
String message;
- String Constant
"Good Morning World!"
- String Assignment
message = "It's Friday";
- String Has Many Methods for Manipulation
- Most important ones are: length(), indexOf(), substring()
-
int length()
-
int indexOf(String st)
-
String substring(int start, int end)
- Getting String Data from the User
- The TextField class has getText() method.
- Can use:
message = mg.getText();
where mg is a TextField and message is a String.
- Exchanging the Contents of Two Variables
- Example Doing Some String Manipulation
StringPlay.java,
StringPlay.html
- Add More Functions
- Last name first format
- All Capitals (
String toUpperCase())