6 String

6 String - String String A String is any number of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: String String A String is any number of characters including letters, digits, spaces and punctuation String greeting = "Hello There!"; println(greeting); //is the same as println("Hello There!"); A String can be thought of as a “mailbox” to hold text 1 String variables String You would create a String variable when you need to store text that can change String words = "Testing, 1,2,3"; println(words); words = "Is this mic on?"; println(words); 2 Adding Strings Adding The + operator combines Strings together to make one bigger String String s1 = "abc"; String s2 = "xyz"; String s3 = s1 + s2; println(s3); 3 Adding Strings Adding The + operator combines Strings together to make one bigger String String s1 = "abc"; String s2 = "xyz"; String s3 = s1 + s2; println(s3); //Displays abcxyz 4 Adding Strings Adding The + operator combines Strings together to make one bigger String String s1 = "abc"; String s2 = "xyz"; String s3 = s1 + s2; println(s3); s3 = s2 + s1; println(s3); 5 Adding Strings Adding The + operator combines Strings together to make one bigger String String s1 = "abc"; String s2 = "xyz"; String s3 = s1 + s2; println(s3); s3 = s2 + s1; println(s3); //Displays xyzabc 6 Adding Strings Adding The + operator is also useful for labeling output Let’s say I’m debugging, and I want to know what is i Let’s say I’m debugging, and I want to know what is the dogs variable int dogs = 3; 7 Adding Strings Adding I could use the + operator to label the output so I know what I’m looking at int dogs = 3; println("There are "+dogs+" dogs."); 8 Adding Strings Adding The + operator is also useful for labeling output int dogs = 3; println("There are "+dogs+" dogs."); +" dogs. //Displays There are 3 dogs //Displays There dogs The + operator creates one big String of all the things that are added together 9 ...
View Full Document

Ask a homework question - tutors are online