title: Java print string and int on same line
body: <p>I was trying to print a string and int on a same line. But I get an error. I know my way around this error but why does the line <code>System.out.println("This is a string: %i", c2.a);</code>gives error whereas the line <code>System.out.println("This is class method" + c2.a );</code> gives the correct output. Below is my code.</p>
  
  <pre><code>public class MyClass
  {
    private int a;
    public double b;
  
    public MyClass(int first, double second)
    {
      this.a = first;
      this.b = second;
    }
  
    // new method
    public static void incrementBoth(MyClass c1) {
      c1.a = c1.a + 1;
      c1.b = c1.b + 1.0;
    }
  
    //pass by valuye therefore no change
    public static void incrementA(int a)
    {
      a = a+1;
    }
  
    public static void main(String[] args)
    {
      MyClass c1 = new MyClass(10, 20.5);
      MyClass c2 = new MyClass(10, 31.5);
      // different code below
      incrementBoth(c2);
      incrementA(c1.a);
      System.out.println("This is a object passing: %i",c2.a);
      System.out.println("This is object passing: " + c2.a );
      System.out.println("This is pass by value: %d",c1.a);
    }
  }
  </code></pre>
  
  <p>My other question is does the line <code>incrementBoth(c2)</code> changes value of c2 because here whole object is passed to the method rather than passing by value in <code>incrementA(c1.a)</code></p>