Java Programming Question
1
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.
2
Name:
Anonymous
2011-06-21 6:29
Value 1 count 2
3
Name:
Anonymous
2011-06-21 6:29
If you have the code why don't you just run it?
4
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?
5
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.
6
Name:
Anonymous
2011-06-21 6:50
>>5
Thank you! That clears everything up.
7
Name:
Java Suit
2011-06-21 6:54
JAVA
8
Name:
Anonymous
2011-06-21 7:34
Get the fuck out of /prog/ , ``please".
9
Name:
Anonymous
2011-06-21 8:00
"value: 1 + count: 2"
10
Name:
Anonymous
2011-06-21 8:08
11
Name:
Anonymous
2011-06-21 14:36
OP has got to be an 8 year old kid, right? Good luck, kiddo
12
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.
13
Name:
java scripts
2011-06-22 2:09
var value = 0;
var count = 1;
value = count++;
alert("value: "+ value + " + count: " + count );