Syllabus - Introduction to Programming in Java | CSIS 110, Study notes of Javascript programming

Material Type: Notes; Professor: Hanks; Class: Intro to Programming in Java; Subject: Computer Science Info Systems; University: Fort Lewis College; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-ztv
koofers-user-ztv 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSIS 110 - Lecture 17
Last time
Scanner class
Strings
We looked at the charAt, indexOf, lastIndexOf, toUpperCase, and toLowerCase methods.
Let's look at a few more:
substring( int startPos, int endPos ) – return the String that
consists of the characters in the original String from startPos to endPos – 1.
The new String does NOT contain the character at endPos. An easy way to
remember this: the length of the new String is the difference between endPos and
startPos.
substring( int startPos ) – return the substring of the original String
starting at startPos and continuing to the end of the original String.
trim() – return a new String which has whitespace trimmed off the ends of the
original String. This doesn't remove all whitespace from a String – only at the ends.
Let's try some examples:
Print a String in reverse order
Print the location of every 'C' in a DNAsequence
pf2

Partial preview of the text

Download Syllabus - Introduction to Programming in Java | CSIS 110 and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 - Lecture 17

Last time Scanner class Strings We looked at the charAt, indexOf, lastIndexOf, toUpperCase, and toLowerCase methods. Let's look at a few more: substring( int startPos, int endPos ) – return the String that consists of the characters in the original String from startPos to endPos – 1. The new String does NOT contain the character at endPos. An easy way to remember this: the length of the new String is the difference between endPos and startPos. substring( int startPos ) – return the substring of the original String starting at startPos and continuing to the end of the original String. trim() – return a new String which has whitespace trimmed off the ends of the original String. This doesn't remove all whitespace from a String – only at the ends. Let's try some examples: Print a String in reverse order Print the location of every 'C' in a DNAsequence

Lab Make a new class named Lab13. Write the following method: public String extract( String s, char start, char end ) This method returns the substring of s ranging from the first instance of the start char to the last instance of the end char. For example, if you invoked extract like this: extract( "Brian Hanks", 'a', 'n' ); it would return "anHan". The extract method returns an empty String ("") if any of the following occurs:

  • s does not contain the start char
  • s does not contain the end char
  • the index of the end char is less than the index of the start char Email the file Lab13.java to me – use the subject "Lab 13".