|
|
Strings Lab
Class StringRunner
/*
* StringRunner.java
*
* Created on July 18, 2005, 5:28 PM
*/
package stringexcercizes;
/**
*
* @author jonesbr
*/
public class StringRunner {
/** Creates a new instance of StringRunner */
public StringRunner() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// create an object instance of class StringExamples.
StringExamples se = new StringExamples();
// call the method exercise on this newly-created object.
se.exercise();
}
}
Class StringExamples
/*
* StringExamples.java
*
* Created on July 18, 2005, 5:29 PM
*/
package stringexcercizes;
/**
*
* @author jonesbr
*/
public class StringExamples {
/** Creates a new instance of StringExamples */
public StringExamples() {
}
/**
* This method tests out some common string methods.
*
*/
public void exercise() {
// our test String.
String simple = "Welcome to Java!";
// find the length.
System.out.println("Length: " + simple.length());
// find the character at position 6
System.out.println("Character at 6: " + simple.charAt(6) );
// print a substring
System.out.println("Substring at positions 2, 5: " + simple.substring(2, 5));
}
}
|