Where a + symbol has a String on one or either sides, the + symbol is used as the concatenation operator. But where a + symbol has a number on either side, the + symbol is used as the addition operator.
Need to concatenate 2 adjacent numbers? Return the String value of one of the numbers in the following way:
Showing posts with label Concatenation. Show all posts
Showing posts with label Concatenation. Show all posts
Sunday, September 9, 2012
Sunday, June 3, 2012
The concatenation operator
DOWNLOAD THE CODE: ConcatPkg
The concatenation operator is the addition symbol +.
Concatenation is the act of joining multiple values together to form a single String.
Here's the output:
The concatenation operator is the addition symbol +.
Concatenation is the act of joining multiple values together to form a single String.
Here's the output:
Note! The addition symbol is also used as the addition operator! If the addition symbol is placed between 2 numbers, it will treat the expression as an addition expression!
Saturday, June 2, 2012
Escape Sequences
From "Characters (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)" ( http://bit.ly/LUgCyw )
Sunday, March 18, 2012
What is a String?
DOWNLOAD THE CODE: IntroToStringPkg.zip
A string is a collection of any keyboard characters such as "I love chocolate 100 times more than you !!!"
Where a String has not been assigned a value, by default it's value is null.
In the example below, 2 Strings are created (lines 1 and 2).
The 3rd statement concatenates (joins) the 2 Strings together (using the addition character).
The fourth statement returns the number of characters in the String called firstName, by calling the String length() function (all Strings have this function, it returns an int).
The fifth line finds the first character of the String by calling the String charAt() function (all Strings have this function, returns the character at the specified position).
The final statement concatenates all of the values together and prints to screen.
A variable, such as String, can be declared in one statement and assigned a value in another statement, as below:
String myString;
myString = "This is a String!";
...or it can be declared and assigned a value in a single statement:
String myString = "This is a String!";
Literal String values (the actual charcters) are always enclosed in double quotation marks.
See also: "Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)" ( http://bit.ly/K4kbDz )
"String (computer science) - Wikipedia, the free encyclopedia" ( http://bit.ly/AgRVuH )
Here's a cat:
A string is a collection of any keyboard characters such as "I love chocolate 100 times more than you !!!"
Where a String has not been assigned a value, by default it's value is null.
In the example below, 2 Strings are created (lines 1 and 2).
The 3rd statement concatenates (joins) the 2 Strings together (using the addition character).
The fourth statement returns the number of characters in the String called firstName, by calling the String length() function (all Strings have this function, it returns an int).
The fifth line finds the first character of the String by calling the String charAt() function (all Strings have this function, returns the character at the specified position).
The final statement concatenates all of the values together and prints to screen.
The output:
A variable, such as String, can be declared in one statement and assigned a value in another statement, as below:
String myString;
myString = "This is a String!";
...or it can be declared and assigned a value in a single statement:
String myString = "This is a String!";
Literal String values (the actual charcters) are always enclosed in double quotation marks.
See also: "Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)" ( http://bit.ly/K4kbDz )
"String (computer science) - Wikipedia, the free encyclopedia" ( http://bit.ly/AgRVuH )
Here's a cat:
Subscribe to:
Posts (Atom)





