Arithmetic - plus a variety of

Among the four operations plus sign "+" There are three common usage:

1. For the values for that addition .
2. For character type char , in computing before, char will be promoted to become int , and then re- calculate.
comparison table between the character type char, and int type numbers,: ASCII, Unicode
3. For string String (first letter capitalized, not keyword), the plus sign represents a string connecting operation .
When any data type and the connection string, the result will become a string

Code demonstrates:

 

. 1  public  class Demo05Plus {
 2      public  static  void main (String [] args) {
 . 3          // Variables of type string substantially using
 4          // Data type variable name = data value; 
. 5          String str1 = "the Hello" ;
 . 6          the System.out .println (str1); // the Hello 
. 7          
. 8          System.out.println ( "the Hello" + "World"); // the HelloWorld 
. 9          
10          String str2 = "the Java" ;
 . 11          // String int + -> String 
12 is          the System .out.println (20 is str2 +); // Java20
13 is          
14          // priority issue
 15          // String int + int +
 16          // String + int
 . 17          // String 
18 is          System.out.println (str2 20 is + 30 +); // Java2030 
. 19          
20 is          System.out.println ( + str2 (20 is + 30)); // Java50 
21 is      }
 22 is }

 

Output:

  Hello

  HelloWorld

  Java20

  Java2030

  Java50

 

Guess you like

Origin www.cnblogs.com/chenliqiang/p/11447287.html