|
Live2Win
United States6657 Posts
|
Calgary25955 Posts
I think X _= Y means X = X _ Y So in your example: a = a*b
|
yeah... x+=5 is x=x+5
so i guess what chill said
|
|
If this is a Java question, why don't you open up eclipse or whatever you use, and try some of those expressions?
|
|
you ask about multiplication but not modulo? strange
|
On February 02 2008 13:51 fusionsdf wrote:you ask about multiplication but not modulo? strange modulus doesn't really matter in this question
|
Live2Win
United States6657 Posts
On February 02 2008 13:51 fusionsdf wrote:you ask about multiplication but not modulo? strange I understand modulo :p
I actually looked this up and found out. Thanks for helping out guys.
|
yeah but I always found +=, -=,/=, *= intuitive.
modulo confused me quite a bit when I first saw it :O
|
The line c = a % 3 + c / b; is useless here. -.-
|
On February 02 2008 14:03 FreeZEternal wrote: The line c = a % 3 + c / b; is useless here. -.- exactly that's why b=2 and c=1
|
Live2Win
United States6657 Posts
On February 02 2008 14:19 Saracen wrote:Show nested quote +On February 02 2008 14:03 FreeZEternal wrote: The line c = a % 3 + c / b; is useless here. -.- exactly that's why b=2 and c=1 why? I don't get why it's useless.
a *= b; a = a * b a = 5 * 2 so, a = 10
c = a % 3 + c / b c = (10 % 3) + (6 / 2) c = (1) + (3) so, c = 4
c = b--; c = 2-- so, c = 2 b = 1
Thus, a = 10, b = 1, c = 2
I'm not sure what "d" is. What's the default for that value?
|
On February 02 2008 14:25 Live2Win wrote:Show nested quote +On February 02 2008 14:19 Saracen wrote:On February 02 2008 14:03 FreeZEternal wrote: The line c = a % 3 + c / b; is useless here. -.- exactly that's why b=2 and c=1 why? I don't get why it's useless. a *= b; a = a * b a = 5 * 2 so, a = 10 c = a % 3 + c / b c = (10 % 3) + (6 / 2) c = (1) + (3) so, c = 4 c = b--; c = 2-- so, c = 2 b = 1 Thus, a = 10, b = 1, c = 2 I'm not sure what "d" is. What's the default for that value?
because you are setting c to some long equation
and then the very next step you set c to one less than b
In other words, you saved a value to c, didnt use it, and saved over it
as for d, it depends on the language. Java protects you, so it should be 0.0
|
for: public static void main(String args[]) { char alpha; alpha = “g”; }
you have to use single quotes for chars (at least you do in C++ and I assume its the same here)
so it should be public static void main(String args[]) { char alpha; alpha = 'g'; }
or you can combine the two steps to
public static void main(String args[]) { char alpha = 'g'; }
which will initialize it with a value.
as a follow up to d, java protects you, but some languages don't. be careful relying on the value of a variable you didnt give a value to yet :O
|
For people saying the final variables are c=1 and b=2, look at it more carefully. b-- means evaluate b, then decrement b. At the start of that step b = 2, so c is set to 2, then b is decremented, giving c = 2 and b = 1. Most of you are doing c = b - 1; which is very different from c = b--;. For c to end up 1 using the -- operator, it would need to be c = --b; which would set both b and c to 1.
|
+ Show Spoiler +double a = 5, b = 2, c = 6, d;
a *= b; // equivalent to a = a * b, or a = 5 * 2, or a = 10
c = a % 3 + c / b; // equivalent to c = (10 mod 3) + (6 / 2), or c = (1) + (3), or c = 4
c = b– –; //equivalent to c = b; b = b - 1, or c = 2, b = 2 - 1, or c = 2; b = 1
End values: a = 10 b = 1 c = 2 d is uninitialized.
Also, to set char alpha to lowercase g:
this will work: char alpha = 'g';
this will also work: char alpha; alpha = 'g';
this also will work: char alpha; alpha = 71; // 71 is ASCII for 'g'
|
Um, what? You'll get a compile error if you try to access d, I think. d is uninitialized.
If d wasn't a primitive type, it would be equal to null. Since it is a primitive type, its value is uninitialized and you'd get a compile error.
|
oh damn im way too late huh? T_T anyway bottleabuser is right. compiler would kick your face for trying to make use of d when there's no gaurantee that it won't be null. However, assuming d was initialized as 0, you'd get a = 10 b = 1 c = 2 d = 0 and the char one .. so ez. char alpha = 'g';
is this for school?
|
it's post decrement,
so c is 1 more than b.
and BottleAbuser is right. You can't compile your code unless you have d initialized.
|
|
|
|