/***************************************************************** * Program: Test String's methods * Programmer: Insert your name here * * Class: COMP 110-001 Instructor: Yi Hong * * Pledge: I have neither given nor received unauthorized aid * on this program. (signature on file) * * Description: This program tests some String methods. * * Input: none * * Output: messages showing the output of various functions ******************************************************************/ public class TestStringMethods { public static void main(String[] args) { /* Let's see what's the output of the following code */ String greeting = "How do you do"; System.out.println(greeting + "Seven of Nine."); /* Using String methods */ String test1 = "abcdefg"; System.out.println(test1.length()); System.out.println(test1.charAt(1)); System.out.println(test1.substring(3)); /* Using Escape characters in Strings */ System.out.println("abc\ndef"); System.out.println("abc\\ndef"); /* What does the toUpperCase function do in String? */ String test2 = "Hello John"; test2 = test2.toUpperCase(); System.out.println(test2); /* Testing the equality of 2 Strings */ String s1 = "Hello John"; String s2 = "hello john"; System.out.println(s1.equals(s2)); s1 = s1.toLowerCase(); s2 = s2.toLowerCase(); System.out.println(s1.equals(s2)); } }