Java String concatenate with numeric values

Question

What is the output of the following code?

public class Main {
   public static void main(String[] args) {
      System.out.println("1" + 1);
      System.out.println('1' + 1);
      System.out.println("1" + 1 + 1);
      System.out.println("1" + (1 + 1));
      System.out.println('1' + 1 + 1);

   }//from w ww . j  a v  a 2s  .c  om
}


11
50
111
12
51

What is the output of the following code?

public class Main {
   public static void main(String[] args) {
      System.out.println(1 + "demo2s.com " + 1 + 1);
      System.out.println(1 + "demo2s.com " + (1 + 1));
      System.out.println(1 + "demo2s.com " + ('\u0001' + 1));
      System.out.println(1 + "demo2s.com " + 'a' + 1);

   }
}


1demo2s.com 11
1demo2s.com 2
1demo2s.com 2
1demo2s.com a1



PreviousNext

Related