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

Plus three common usage

  • For value for that addition.
  • For character types, char, before calculating, char will be promoted to become int, and then calculated. Comparison table between the character char type, numeric type int and,: ASCII, Unicode
  • For string String (first letter capitalized, not keyword), the plus sign on behalf of string concatenation. When any data type and the connection string, the result will become a string

Code Example

public  class Demo05Plus {
     public  static  void main (String [] args) {
         char C = 'I' ;
         // char to an int type and the result is a large range of the data type int 
        System.out.println (C + 2 ) ;
         // variables of type string data type basic variable name = data value; 
        string str1 = "the Hello" ; 
        System.out.println (str1); 
        System.out.println ( "the Hello" + "World"); / / the HelloWorld 
        String str2 = "the Java" ;
         // String int + -> String 
        System.out.println (+ 20 is str2); // Java20
        // priority issues
         // String + int + int
         // String + int
         // String 
        System.out.println (str2 + 20 + 30); // Java2030 
        System.out.println (str2 + (20 + 30)) ; // Java50 
    } 
}

Results of the

 

Guess you like

Origin www.cnblogs.com/wurengen/p/11204136.html