We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java Exception Handling
Java Exception Handling
+ 1 comment More exception handling problems please :)
+ 0 comments This problem is shameful, for a lot of reasons, some of them already exposed below.
We can not teach people to use Java with a problem that makes so many basic errors (Class name starting in lowercase, variable with a single letter and in uppercase, which is usually reserved for constants, bad usage of try-catch for controlling the flow of the program, etc.).
I though there was a review process or something for problems, but I have seen a few problems in the Java section that make me think otherwise...
+ 2 comments public long power(int n, int p) throws Exception{ long result; if(n==0 && p==0){ throw new Exception("n and p should not be zero."); } if(n<0 || p<0){ throw new Exception("n or p should not be negative."); } result=(long)Math.pow(n,p); return result; }
+ 0 comments class MyCalculator{ public static int power(int n, int p) throws Exception{ if(n < 0 || p < 0){ throw new Exception ("n or p should not be negative."); } else if (n == 0 && p == 0){ throw new Exception ("n and p should not be zero."); } else { return ((int)Math.pow(n,p)); } } }
+ 12 comments Hope this helps..
class MyCalculator{ public static int power(int n, int p) throws Exception{ if(n < 0 || p < 0){ throw new Exception ("n and p should be non-negative"); } else { return ((int)Math.pow(n,p)); } } }
Load more conversations
Sort 220 Discussions, By:
Please Login in order to post a comment