because you are suppose to run this program using command line then only you will get the value of ParaStrNum I ran your program successfully.Dj Galla wrote:There is no error in NetBeans when I view the code, but I do get the following message when the program is run:
Ganesh Patekar wrote:
because you are suppose to run this program using command line then only you will get the value of ParaStrNum I ran your program successfully.Dj Galla wrote:There is no error in NetBeans when I view the code, but I do get the following message when the program is run:
Ganesh Patekar wrote:
because you are suppose to run this program using command line then only you will get the value of ParaStrNum I ran your program successfully.Dj Galla wrote:There is no error in NetBeans when I view the code, but I do get the following message when the program is run:
Campbell Ritchie wrote:if (args.length > 0 && (numberScan = new Scanner(args[0])).hasNextInt())[/code]
Dj Galla wrote:Here is what I have so far... the program works, but shows an error when I enter a non integer...
Carey Brown wrote:When you say "shows an error" you should cut-n-paste the error text into a post.
Carey Brown wrote:On line 12 you have
theNum = 0; // If Error, Set to 0
So, you return 0, then subtract 1, that gives you a -1, then you try to use that as an array index, and there is no valid index less than zero.
Carey Brown wrote:...there is no valid index less than zero.
Did you leave the closing code tag in when trying to run the code? There was an error in what I wrote originally, but I had corrected it long before you tried out the code. When I wrote a something() method, my code ran normally.Dj Galla wrote:This line is showing an error in NetBeans before running the project...
You have not sorted out the problem of negative numbers.Dj Galla wrote:
Carey Brown wrote:...there is no valid index less than zero.
Fixed it. And it's running fine...
Where? I can's see any ands or ors.
(I also fixed replaced the AND with OR). . . .
Campbell Ritchie wrote:You have not sorted out the problem of negative numbers.
Campbell Ritchie wrote:Where? I can's see any ands or ors.
Campbell Ritchie wrote:If anything goes wrong, you are returning 0 which we already know is an invalid
Campbell Ritchie wrote:You are also using Exceptions instead of if‑else, which is simply inefficient.
All things are lawful, but not all things are profitable.
All things are lawful, but not all things are profitable.
Just a bit of incredibly complicated and illegible code, which I think will return a 0 and you are then ignoring it. The user enters incorrect input and never finds out about it. And you still think no issues?Dj Galla wrote:. . . Before, the issue was coming from a negative number being an array key (i.e. array[-1]). When w.parseStr(args) is run (line 8 of class DWarsPara), it returns a number from 0 to 147. I then added a conditional if statement to check if parNum is not equal to 0 (line 10 of class DWarsPara), and if true, it runs the conditional block using parNum (with only values of 1 to 147). That block enters array keys 0-146 - no negative numbers, and no issues.
And you are subtracting 1 from all numbers? You have a bit of convoluted code which will confuse everybody who reads it.. . .
Campbell Ritchie wrote:If anything goes wrong, you are returning 0 which we already know is an invalid
0 is an invalid number? Not sure what you mean ... seems like it works like most numbers, and is fine as an array key. Can you explain?
Didn't you see my earlier post about Scanner#hasNextInt?Campbell Ritchie wrote:You are also using Exceptions instead of if‑else, which is simply inefficient.
Any recommendations you can give are definitely welcome. Not sure how to avoid errors using if-else statements...
Campbell Ritchie wrote:The user enters incorrect input and never finds out about it. And you still think no issues?
Campbell Ritchie wrote:And you are subtracting 1 from all numbers?
Campbell Ritchie wrote:You have a bit of convoluted code which will confuse everybody who reads it.
Campbell Ritchie wrote:Didn't you see my earlier post about Scanner#hasNextInt?
Knute Snortum wrote:Can you reduce in the number of lines in the method to one?
I think that's ugly. Would much rather seeGanesh Patekar wrote:
Why I turned simple code into gnarled one , Agreed! Thank you Carey BrownCarey Brown wrote:I think that's ugly. Would much rather see
Your buns are mine! But you can have this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|