AP Computer Science CH09

plumponionchipsΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

88 εμφανίσεις

String Class






Name: ________________________

AP Computer Science


CH09

Mr. Locascio






Period: _____ Date: ____________



1. Write the output for the following code on a separate sheet of notebook paper.


public class CH09_LAB_StringOutput

{


stat
ic String a;




public static void main(String args[])


{



String b = "";



String c = "We love Java";



String d = "Class of 200
5
";








System.out.println("a = " + a);



System.out.println("b = " + b);



System.out.println("c = " + c);




System.out.p
rintln("c.charAt(1) returns " + c.charAt(1));




System.out.println("c.length() returns " + c.length());






b = c.substring(8) + " " + c.substring(3,6) + " u.";



System.out.println("Now String b = " + b);



System.out.println("c = " + c.toLowerCase());



System.out.println("Now String c = " + c);




System.out.println("d.IndexOf(
\
"2000
\
") returns " + d.indexOf("2000"));



System.out.println("d.IndexOf('2') returns " + d.indexOf('2'));




//refer to your textbook pg 267



if(b.compareTo(c) < 0)




System.
out.println("compareTo < 0");



else if (b.compareTo(c) > 0)




System.out.println("compareTo > 0");



else




System.out.println("compareTo = 0");




d = d.replaceAll("2005", "2006");



System.out.println("Now String d = " + d);



System.out.println("Afte
r d.trim() d = " + d.trim());



System.out.println("After d.toUppercase() d = " + d.toUpperCase());




System.out.println("3 + 4 +
\
" <
\
" + 7 + 8 will display as follows");



System.out.println(3 + 4 + " < " + 7 + 8);





}

}



2.

Complete problems 4,5 and 6

on page 279 in your textbook. Write you answers on notebook paper.