Docsity

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

Toggle sidebar
bg1
CSIS 110 - Lecture 21
Announcements
Quiz Wednesday. Covers material up through today.
Turn in homework.
Homework
Read sections 5.1 โ€“ 5.4 (pages 119 โ€“ 136)
Next Programming Assignment on web site โ€“ read the assignment, we'll discuss it next
time.
Class String
Last time we started looking at some of the methods in the String class: charAt,
indexOf, lastIndexOf, toUpperCase, and toLowerCase.
Let's look at a few more String methods:
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.
pf2

Partial preview of the text

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

CSIS 110 - Lecture 21

Announcements Quiz Wednesday. Covers material up through today. Turn in homework. Homework Read sections 5.1 โ€“ 5.4 (pages 119 โ€“ 136) Next Programming Assignment on web site โ€“ read the assignment, we'll discuss it next time. Class String Last time we started looking at some of the methods in the String class: charAt, indexOf, lastIndexOf, toUpperCase, and toLowerCase. Let's look at a few more String methods: 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.

Lab Make a new class named Lab16. 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 "an Han". 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 Lab16.java to me โ€“ use the subject "Lab 16". Lab Make a new class named Lab16. 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 Lab16.java to me โ€“ use the subject "Lab 16".