But that's what the compiler is already doing! The quotation mark suggests that a string must be created. When the compiler reaches this piece of text, it simply doesn't understand what it is expected to do. In our case, the quotation marks around the word "Twilight" are inside other quotation marks. And every time the compiler sees ", it expects that the quotation mark will be followed by a second quotation mark, and that the content between them is the text of a string to be created by the compiler. it expects strings to be wrapped in them. The compiler interprets quotation marks in a very specific way, i.e. What do you think the problem could be? And what does it have to do with quotation marks? It seems the compiler is unhappy about something! String myFavoriteBook = new String ("My favorite book is "Twilight" by Stephanie Meyer") I'm 20!") īut what do we do if we need to create a string that itself must contain quotation marks? For example, suppose we want to tell the world about your favorite book: String alex = new String ("My name is Alex. The main thing when creating a string is that the entire sequence must be enclosed in quotation marks: These characters can be any letters, numerals, punctuation marks and so on. Hi! In previous lessons, we've already gotten acquainted with text strings, which are represented by the String class in Java.Īs you probably remember, a string is a sequence of characters.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |