92 Part II: Writing Your Own Java Programs (Web design programs)
92 Part II: Writing Your Own Java Programs Creating New Values by Applying Operators What could be more comforting than your old friend, the plus sign? It was the first thing that you learned about in elementary school math. Almost everybody knows how to add 2 and 2. In fact, in English usage, adding 2 and 2 is a metaphor for something that s easy to do. Whenever you see a plus sign, a cell in your brain says, Thank goodness it could be something much more complicated. So Java has a plus sign. You can use it for several different purposes. You can use the plus sign to add two numbers, like this: int apples, oranges, fruit; apples = 5; oranges = 16; fruit = apples + oranges; You can also use the plus sign to paste Stringvalues together: String startOfChapter = It s three in the morning. I m dreaming about the + history course that I failed in high school. ; System.out.println(startOfChapter); This can be handy because in Java, you re not allowed to make a String straddle from one line to another. In other words, the following code wouldn t work at all: String thisIsBadCode = It s three in the morning. I m dreaming about the history course that I failed in high school. ; System.out.println(thisIsBadCode); The correct way to say that you re pasting Stringvalues together is to say that you re concatenating Stringvalues. You can even use the plus sign to paste numbers next to Stringvalues. int apples, oranges, fruit; apples = 5; oranges = 16; fruit = apples + oranges; System.out.println( You have + fruit + pieces of fruit. );
Here java web hosting you will find professional-grade java web hosting at affordable prices.