VariousStringMethods

VariousStringMethods - System.out.println("Line 6: The...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Program to illustrate the effect of variuos String methods / public class VariousStringMethods { public static void main (String[] args) { String sentence; String str1; String str2; String str3; int index; sentence = "Now is the time for the birthday party"; //Line 1 System.out.println("Line 2: sentence = \"" + sentence + "\""); //Line 2 System.out.println("Line 3: The length of sentence = " + sentence.length()); //Line 3 System.out.println("Line 4: The character at index 16 in " + "sentence = " + sentence.charAt(16)); //Line 4 System.out.println("Line 5: The index of first t in " + "sentence = " + sentence.indexOf('t')); //Line 5
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println("Line 6: The index of for in sentence " + "= " + sentence.indexOf("for")); //Line 6 System.out.println("Line 7: sentence in uppercase = \"" + sentence.toUpperCase() + "\""); //Line 7 index = sentence.indexOf("birthday"); //Line 8 str1 = sentence.substring(index, index + 14); //Line 9 System.out.println("Line 10: str1 = \"" + str1 + "\""); //Line 10 str2 = "Super " + str1; //Line 11 System.out.println("Line 12: str2 = \"" + str2 + "\""); //Line 12 str3 = sentence.replace('t', 'T'); //Line 13 System.out.println("Line 14: str3 = \"" + str3 + "\""); //Line 14 } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Ask a homework question - tutors are online