User Tools

Site Tools


it-artikel:java:demo-assignment-operators-which-way-around

Demo - assignment operators which way around?

I found an interesting Question on one YouTube Video Tutorials and thought about testing it out myself and make a demo to it.

The Original Video was: http://www.youtube.com/watch?annotation_id=annotation_974871&v=TL7tdNp0raE&feature=iv

Question was:

what is the difference between c+=b and c=+b

My Answer to that Question is: thats c=c+1 and the next is c=b. See this little demo:

TestingAssignmentOperators1
/**
 * Messing around with assignment operators
 */
 
/**
 * @author Axel Werner
 *
 */
public class TestingAssignmentOperators1 {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
 
 
		int x;
 
		x = 5;
		System.out.print("x is: ");
		System.out.println(x);
		System.out.print("x+=1 results in: ");
		System.out.println(x+=1);
		System.out.print("Now x is: ");
		System.out.println(x);
 
		System.out.println("--------------------------------------");
 
		x = 5;
		System.out.print("x is: ");
		System.out.println(x);
		System.out.print("x=+1 results in: ");
		System.out.println(x=+1);
		System.out.print("Now x is: ");
		System.out.println(x);
 
		System.out.println("--------------------------------------");
 
		System.out.println("That means:");
		System.out.println("               x+=1    is like x=x+1");
		System.out.println("while          x=+1    is like x=1");
		System.out.println("--- THE END ---");
 
 
	}
 
}
it-artikel/java/demo-assignment-operators-which-way-around.txt · Last modified: 2022-08-31 12:30 by 127.0.0.1