StringManips

StringManips - / / / / / * FILE: StringManips.java Purpose:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// *************************************************************** // FILE: StringManips.java // // Purpose: Test several methods for manipulating String objects // *************************************************************** import java.util.Scanner; public class StringManips { public static void main (String[] args) { String phrase = new String ("This is a String test."); int phraseLength; // number of characters in the phrase String int middleIndex; // index of the middle character in the String String firstHalf; // first half of the phrase String String secondHalf; // second half of the phrase String String switchedPhrase; // a new phrase with original halves switched String middle3; // middle 3 characters of the phrase String city, state; // hometown city and state Scanner scan = new Scanner (System.in); // compute the length and middle index of the phrase phraseLength = phrase.length(); middleIndex = phraseLength / 2; // get the substring for each half of the phrase firstHalf = phrase.substring(0,middleIndex);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

StringManips - / / / / / * FILE: StringManips.java Purpose:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online