Results 1 to 12 of 12
Thread: Errors while using parseInt
- 07-25-2013, 07:41 AM #1
Member
- Join Date
- Jul 2013
- Posts
- 18
- Rep Power
- 0
Errors while using parseInt
I probably made a dumb mistake, but hey, that's why I'm posting on New To Java.
Java Code:package practiceapplication; import static java.lang.Integer.parseInt; class Practiceapplication{ int addition(String arguments[]){ int sum = 0; if (arguments[0] == "+" ) for(int x = 0; x < arguments.length; x++){ arguments = new Integer.parseInt(arguments); sum += arguments[x]; } return sum; if (arguments[0] == "*") { for(int x =0; x < arguments.length; x++){ arguments = new Integer.parseInt(arguments); sum *= arguments[x]; } } return sum; } }
This is not the complete object, but you get the idea.
What am I doing wrong?
It says parseInt cannot be found.
- 07-25-2013, 08:30 AM #2
Re: Errors while using parseInt
The new keyword is used in conjunction with a constructor call, to instantiate and object. Not with a method call, as you have used it.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 07-25-2013, 08:32 AM #3
Re: Errors while using parseInt
And after you've corrected that, read the API for the Integer class and see what parameter the parseInt(...) method expects, and what it returns. Hint: Neither of those are a String array.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 07-25-2013, 08:38 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Errors while using parseInt
... and finally, you can't compare two Strings for equality with the == operator; use the String.equals( ... ) method instead.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 07-25-2013, 10:00 AM #5
Member
- Join Date
- Jul 2013
- Posts
- 18
- Rep Power
- 0
Re: Errors while using parseInt
You CAN use "==" operator when comparing two strings in Java 7 (java 1.7+)
Aren't they arrays? Since in the main method (which I didn't include in this code), I have declared "String[] arguments"
- 07-25-2013, 10:05 AM #6
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Errors while using parseInt
The only dumb mistake I see you making is not listening to the people who are giving you advice.
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 07-25-2013, 10:41 AM #7
Member
- Join Date
- Jul 2013
- Posts
- 18
- Rep Power
- 0
Re: Errors while using parseInt
I'm just questioning them, dumbshit.
- 07-25-2013, 10:45 AM #8
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Errors while using parseInt
Gee name calling, now you're getting somewhere.
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 07-25-2013, 10:58 AM #9
Member
- Join Date
- Jul 2013
- Posts
- 18
- Rep Power
- 0
Re: Errors while using parseInt
Why can't you just go bother someone else.
- 07-25-2013, 10:59 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Errors while using parseInt
Please do not ask for code as refusal often offends.
** This space for rent **
- 07-25-2013, 11:02 AM #11
Member
- Join Date
- Jul 2013
- Posts
- 18
- Rep Power
- 0
Re: Errors while using parseInt
Okay, but how do I specify that I'm looking for an operator at arugments[0]?
Thanks for actually help me, unlike the other guy.
- 07-25-2013, 11:17 AM #12
Similar Threads
-
How to use if/else with parseint
By asai in forum New To JavaReplies: 4Last Post: 06-20-2012, 07:43 PM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 01:36 AM -
parseInt Exception errors
By TIMBERings in forum New To JavaReplies: 5Last Post: 12-10-2009, 10:11 AM -
parseInt
By trefoil in forum New To JavaReplies: 4Last Post: 09-09-2009, 08:12 PM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 02:51 AM
Bookmarks