Results 1 to 6 of 6
  1. #1
    cloudracer is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Java difference between x + and x+

    What's the difference between + x and +x when it comes to system.out.println() for example:

    Java Code:
    public class ChangeParam {
    
    	public static void main(String[] args) {
    		int x = 1;
    		double y = 3.4;
    		System.out.println(x+" "+y);
    		changeUs(x, y);
              System.out.println(x+" "+y);		
    	}
    	
    	public static void changeUs(int x, double y) {
    		x = 0;
    		y = 0.0;
    		changeMe(x, y);
    		System.out.println(x +" "+y);
    	}
    	
    	public static void changeMe(int x, double y) {
    		x = 2;
    		y = 3.0;
    		System.out.println(x +" "+y);
    	}


    edit - put full code in; as you can see there is a space between the x +

    trying to revise for a test and i don't know if this is a typo or what?
    thank you
    Last edited by cloudracer; 04-26-2014 at 05:56 PM. Reason: Put full code in

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    29

    Default Re: Java difference between x + and x+

    Spaces don't matter here; what exactly is your problem?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Java difference between x + and x+

    Where is the +x?
    In +x, the + would be the unary operator. See: Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
    The only +s I see in the post are the String concatenation operator.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    cloudracer is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Java difference between x + and x+

    I'll post the full code to clear up my question abit more

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    29

    Default Re: Java difference between x + and x+

    Norm's and my reply are still valid; what's the problem?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Java difference between x + and x+

    I prefer spaces around operators. That makes them easier to see.

    thisIsALongName+AnotherLongNameThat+CouldHideTheOp erators
    vs
    thisIsALongName + AnotherLongNameThat + CouldHideTheOperators
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 7
    Last Post: 12-16-2013, 08:15 PM
  2. Difference between Java Card and OpenPGPCard
    By Lord Tiki Mick in forum Advanced Java
    Replies: 1
    Last Post: 11-23-2012, 08:37 PM
  3. Difference between java v1.5 and v1.6
    By zaniwhoop in forum New To Java
    Replies: 1
    Last Post: 03-20-2012, 10:38 AM
  4. Replies: 1
    Last Post: 11-07-2011, 08:55 PM
  5. Difference between Java...
    By AWPtic in forum New To Java
    Replies: 6
    Last Post: 05-06-2009, 05:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •