CPS 1 - Spring, 1999 - Ramm 1/29/99 #7
Chapt 1. An Introduction to Programming: Coding Decision Trees
- Using Primitive Data Types: Integers
- Correction
- Should initialize (Java sets to 0)
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.
- Example Doing Some String Manipulation
StringPlay.java,
StringPlay.html
- Add More Functions
- Last name first format
- All Capitals (
String toUpperCase())
- Exchanging the Contents of Two Variables