123456789101112131415161718192021222324252627
  1. public class StringExample
  2. { public static void main(String[] args)
  3. { String s1 = "Computer Science";
  4. int x = 307;
  5. String s2 = s1 + " " + x;
  6. String s3 = s2.substring(10,17);
  7. String s4 = "is fun";
  8. String s5 = s2 + s4;
  9. System.out.println("s1: " + s1);
  10. System.out.println("s2: " + s2);
  11. System.out.println("s3: " + s3);
  12. System.out.println("s4: " + s4);
  13. System.out.println("s5: " + s5);
  14. //showing effect of precedence
  15. x = 3;
  16. int y = 5;
  17. String s6 = x + y + "total";
  18. String s7 = "total " + x + y;
  19. String s8 = " " + x + y + "total";
  20. System.out.println("s6: " + s6);
  21. System.out.println("s7: " + s7);
  22. System.out.println("s8: " + s8);
  23. }
  24. }