-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringObjectsAsParameters.java
More file actions
40 lines (36 loc) · 1.92 KB
/
Copy pathStringObjectsAsParameters.java
File metadata and controls
40 lines (36 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.lang.StringBuilder;
// This program illustrates how String objects as parameters work.
public class StringObjectsAsParameters //Line 1
{ //Line 2
public static void main(String[] args) //Line 3
{ //Line 4
String str = "Hello"; //Line 5
StringBuilder str2=new StringBuilder("Hello");
System.out.println("Line 6: str before "
+ "calling the method "
+ "stringParameter: "+ str); //Line 6
stringParameter(str); //Line 7
changeParameter(str2);
System.out.println("Line 8: str after "
+ "calling the method "
+ "stringParameter: " + str + " "+str2); //Line 8
} //end main //Line 9
public static void changeParameter(StringBuilder pStr2)
{
pStr2.delete(0,pStr2.length()).append("Sunnday");
System.out.println(pStr2);
}
public static void stringParameter(String pStr) //Line 10
{ //Line 11
System.out.println("Line 12: In the method "
+ "stringParameter"); //Line 12
System.out.println("Line 13: pStr before "
+ "changing its value: "
+ pStr); //Line 13
pStr = "Sunny Day"; //Line 14
// pStr.delete(0,pStr.length()).append("HH");
System.out.println("Line 15: pStr after "
+ "changing its value: "
+ pStr); //Line 15
} //end stringParameter //Line 16
} //Line 17