Page 1 of 1
About Question enthuware.ocajp.i.v7.2.1397 :
Posted: Sun Dec 28, 2014 12:33 am
by coder007
Typo in the explanation: instead of
y = y/dy => becomes 10/10 i.e. 2
it should be
y = y/dy => becomes 20/10 i.e. 2
Re: About Question enthuware.ocajp.i.v7.2.1397 :
Posted: Sun Dec 28, 2014 1:26 am
by admin
Fixed.
thank you for your feedback!
Re: About Question enthuware.ocajp.i.v7.2.1397 :
Posted: Tue Jan 27, 2015 3:45 pm
by ArnobDe
Please check the code as it failed to compile.
error: illegal character: '\u00a0'
Also, as far as I know local variables(dy, dx) should be initialized at the time of declaration as they do not get default values like that of instance variables.
jdk version: 1.8 update 25
Re: About Question enthuware.ocajp.i.v7.2.1397 :
Posted: Tue Jan 27, 2015 9:37 pm
by admin
Code works fine.
Also, as far as I know local variables(dy, dx) should be initialized at the time of declaration as they do not get default values like that of instance variables.
That is not correct. local variables have to be initialized before they are used (not necessarily at the time of declaration).
-Paul.
Re: About Question enthuware.ocajp.i.v7.2.1397 :
Posted: Wed Jan 28, 2015 12:34 am
by ArnobDe
That is not correct. local variables have to be initialized before they are used (not necessarily at the time of declaration).
Thanks Paul for providing a better understanding of the concept...
However, I'm simply pasting my the code below and I'll be relieved to discover what went wrong..
Code: Select all
public class CrazyMath {
public static void main(String[] args) {
int x = 10, y = 20;
int dx, dy;
try{
dx = x % 5;
dy = y/dx;
}catch(ArithmeticException ae){
System.out.println("Caught AE");
dx = 2;
dy = y/dx;
}
x = x/dx;
y = y/dy;
System.out.println(dx+" "+dy);
System.out.println(x+" "+y);
}
}
Thanks again in advance...
Re: About Question enthuware.ocajp.i.v7.2.1397 :
Posted: Wed Jan 28, 2015 1:28 am
by admin
I am sorry I don't understand what you mean. The error message you posted above indicates that you have special characters in your code. If you copied and pasted the code from ETSViewer, you might get that problem because of space characters.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.1397 :
Posted: Wed Jan 28, 2015 7:16 am
by ArnobDe
Oh, now I get it. I did actually copy pasted it from ETSViewer which might have caused the compiler to throw an error corresponding to space characters as you have mentioned. Guess I'll have to rewrite it.
Thanks again Paul !
Re: About Question enthuware.ocajp.i.v7.2.1397 :
Posted: Mon Feb 02, 2015 10:17 pm
by admin
You can also just copy the special space character from the code and then do a replace all with the regular space character instead of rewriting.