Skip to content

Commit 3eb97d7

Browse files
committed
added ch10 examples
1 parent edd4f88 commit 3eb97d7

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

ch10/Append.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import java.util.Scanner;
2+
public class Append {
3+
public static void main(String[] args) {
4+
Scanner in = new Scanner(System.in);
5+
System.out.println("Enter 10 lines:");
6+
String text = "";
7+
for (int i = 0; i < 10; i++) {
8+
String line = in.nextLine(); // new string
9+
text = text + line + '\n'; // two more strings
10+
}
11+
System.out.print("You entered:\n" + text);
12+
}
13+
}

ch10/Surprise.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Surprise {
2+
public static void main(String[] args) {
3+
String s1 = "Hi, Mom!";
4+
String s2 = "Hi, " + "Mom!";
5+
if (s1 == s2) { // true!
6+
System.out.println("s1 and s2 are the same");
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)