• Post Reply Bookmark Topic Watch Topic
  • New Topic

methods  RSS feed

 
James Barber
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried everything I can. What I have is.
a method that receives a string and returns it as int.
I get a name in main then do the math in here " public static int calculateCharacters(String text)" this is mandatory
then send it back as integer to main to print. I'm self teaching myself and I find quiz's to do.
And they want the calculation in seperate method
please help!

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Barber wrote:please help!

I'm afraid ItDoesntWorkIsUseless (←click).

What's wrong with what you've written? Are you getting an error message? Does it return the wrong value?

Inquiring minds want to know...

However, just from a cursory glance: Where have you initialized the 'count' field that you reference in main()?

Winston
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Barber wrote:a method that receives a string and returns it as int.

Do you mean parsing a String? Like converting String "1234" to numerical value 1234?
Because you've got a method that returns a length of a string, so for a string "1234" it would return 4.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:
James Barber wrote:a method that receives a string and returns it as int.

Do you mean parsing a String? Like converting String "1234" to numerical value 1234?
Because you've got a method that returns a length of a string, so for a string "1234" it would return 4.



Also, the method is unused. There isn't any code that calls the method.

Henry
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!