DINO_CH

Untitled

Feb 10th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. public class MatchStrings {
  2.  public static void main(String[] args) {
  3.  String string1 = “Too many “;
  4.  String string2 = “cooks”;
  5.  String string3 = “Too many cooks”;
  6.  // Make string1 and string3 refer to separate strings that are identical
  7.  string1 += string2;
  8.  // Display the contents of the strings
  9.  System.out.println(“Test 1);
  10.  System.out.println(“string3 is now:+ string3);
  11.  System.out.println(“string1 is now:+ string1);
  12.  if(string1 == string3) { // Now test for identity
  13.  System.out.println(“string1 == string3 is true.” +
  14.  “ string1 and string3 point to the same string”);
  15.  } else {
  16.  System.out.println(“string1 == string3 is false.” +
  17.  “ string1 and string3 do not point to the same string”);
  18.  }
  19.  // Now make string1 and string3 refer to the same string
  20.  string3 = string1;
  21.  // Display the contents of the strings
  22.  System.out.println(“\n\nTest 2);
  23. System.out.println(“string3 is now:+ string3);
  24.  System.out.println(“string1 is now:+ string1);
  25.  if(string1 == string3) { // Now test for identity
  26.  System.out.println(“string1 == string3 is true.” +
  27.  “ string1 and string3 point to the same string”);
  28.  } else {
  29.  System.out.println(“string1 == string3 is false.” +
  30.  “ string1 and string3 do not point to the same string”);
  31.  }
  32.  }
Advertisement
Add Comment
Please, Sign In to add comment