| Contact PSVM (Q & A) | Notes Below Audio | [toc] [prev] Slide 7 of 17 [next] |
|
|
| 1, 2, 3, 4, 5, 6, [7 (top)], 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, [Lab] |
|
Notes for Slide 07 A String value can contain both normal and "Special" characters. This slide explains the special characters. We mentioned earlier that a String value must begin and end on the same line of your program. You might ask, "Using this rule, how could I specify that I want to have many lines in my String value?" The answer is to type two characters into your String value in your program: a backslash: \ :and an en character: n :. Spoken as, "backslash-n". When your program is run, if you output a String that contained a backslash-n, instead of outputting the two characters: \n :you would instead see a new line. You might also notice that a quote character: " :is used to specify the end of your String value. The natural question to ask is, "How would I include a quote character in my String value without Java thinking that I want to end my String value?" The answer is to put a backslash character: \ :in front of a quote character: " :so that Java knows that you want the quote character to be part of your String value. Given that a backslash character: \ :is used to help specify special characters such as a new line and a quote, your next question could be, "What if I wanted to have a backslash character in my String value? For example, what if I wanted to put both a backslash and a quote inside my String value and I wanted both the backslash and the quote to appear in my String value?!" The answer is to type two backslash characters together, such as: \\ :and Java will know that you want to put a backslash character into your String value. The slide ends with an example of how to output a previous example that uses two lines of output even though the String value is specified on just one line. 1, 2, 3, 4, 5, 6, [7 (top)], 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, [Lab] |