About Question enthuware.ocajp.i.v7.2.1397 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
coder007
Posts: 25
Joined: Wed Dec 17, 2014 9:29 pm
Contact:

About Question enthuware.ocajp.i.v7.2.1397 :

Post 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

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1397 :

Post by admin »

Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

ArnobDe
Posts: 8
Joined: Tue Jan 27, 2015 3:33 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1397 :

Post 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

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1397 :

Post 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.
If you like our products and services, please help us by posting your review here.

ArnobDe
Posts: 8
Joined: Tue Jan 27, 2015 3:33 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1397 :

Post 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...

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1397 :

Post 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.
If you like our products and services, please help us by posting your review here.

ArnobDe
Posts: 8
Joined: Tue Jan 27, 2015 3:33 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1397 :

Post 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 !

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1397 :

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests