Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java Programming Question

Name: Anonymous 2011-06-21 6:24

What does the following java code output?

int value = 0;
int count = 1;
value = count++;
System.out.println("value: "+ value + " + count: " + count );

I think it's;
value: 2 count: 1

Is this right? If it's not can someone please explain the answer to me.  Thank you.

Name: Anonymous 2011-06-21 6:29

Value 1 count 2

Name: Anonymous 2011-06-21 6:29

If you have the code why don't you just run it?

Name: Anonymous 2011-06-21 6:34

>>3
I don't have a java program on my computer.  Do you know of any online?

>>2
So does the "++" only effect the variable it's attached to?

Name: Anonymous 2011-06-21 6:43

>>4


int foo;
int bar;

bar = 1;
foo = bar++;   // foo becomes 1, bar becomes 2

bar = 1;
foo = ++bar;   // foo becomes 2, bar becomes 2


Prefix ++ increments and returns the _new_ value.
Postfix ++ increments and returns the _old_ value.

Name: Anonymous 2011-06-21 6:50

>>5
Thank you! That clears everything up.

Name: Java Suit 2011-06-21 6:54

JAVA

Name: Anonymous 2011-06-21 7:34

Get the fuck out of /prog/, ``please".

Name: Anonymous 2011-06-21 8:00

"value: 1 + count: 2"

Name: Anonymous 2011-06-21 8:08

>>5

Have an upvote, sir

Name: Anonymous 2011-06-21 14:36

OP has got to be an 8 year old kid, right? Good luck, kiddo

Name: Anonymous 2011-06-21 15:14

>>5
Which value you stupid fucker? Ya see, not every language can be as cool as Haskell. Now I see why you work some shit hourly job at a hick firm. You still suck. Go back to playing with your sister's barbie dolls you mental midget.

Name: java scripts 2011-06-22 2:09

var value = 0;
var count = 1;
value = count++;
alert("value: "+ value + " + count: " + count );

Don't change these.
Name: Email:
Entire Thread Thread List