labs
This commit is contained in:
21
labs/lab3/StringPlay.java
Normal file
21
labs/lab3/StringPlay.java
Normal file
@ -0,0 +1,21 @@
|
||||
// **************************************************
|
||||
// StringPlay.java
|
||||
//
|
||||
// Play with String objects
|
||||
// **************************************************
|
||||
public class StringPlay
|
||||
{
|
||||
public static void main (String[] args)
|
||||
{
|
||||
String college = new String ("PoDunk College");
|
||||
String town = new String ("Anytown, USA"); // part (a)
|
||||
int stringLength;
|
||||
String change1, change2, change3;
|
||||
stringLength = college.length(); // part (b)
|
||||
System.out.println (college + " contains " + stringLength + " characters.");
|
||||
change1 = college.toUpperCase(); // part (c)
|
||||
change2 = change1.replace("O","*"); // part (d)
|
||||
change3 = college.concat(", ").concat(town); // part (e)
|
||||
System.out.println ("The final string is " + change3);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user