

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CS 1054 Introduction to Programming in Java Laboratory Exercise 2
Page 1 of 2
Purpose : This exercise is to familiarize you with some of the String methods in Java as well as the concepts of cascading and composition.
To Receive Credit : Show the TA your working program before leaving class.
Activities :
import java.io.*; class StringMethods { public static void main(String[] arg) { String poem1 = “ Tell me not, in mournful numbers ”; //use a tab String poem2 = “Life is but an empty dream! ”; String poem3 = “For the soul is dead that slumbers, ”; String poem4 = “And things are not what they seem.”; System.out.println (poem1); } // end main } // end StringMethods
CS 1054 Introduction to Programming in Java Laboratory Exercise 2
Page 2 of 2
g. Using the appropriate String method, print only the phrase “me not,” from poem1. h. Create a new String using part of poem1 that reads “Students sigh, in mournful numbers”. Print this new String. (Hint: You may need to create new variables to hold intermediate results, including possibly the phrase “Students sigh”).