• Post Reply Bookmark Topic Watch Topic
  • New Topic

passing in string of an array to an int method not working help  RSS feed

 
Sam Jun
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I was doing some problem sets from the book, and I came across a function that was I not able to get solve. Need some help with it.

Basically, I wrote a static methods that is accepting any string of arrays; however, it returns an array of integers. Whenever I pass an string of arrays, I am not getting expected out put.

Someone please advice.


 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Jun wrote:Hello, I was doing some problem sets from the book, and I came across a function that was I not able to get solve. Need some help with it.

Basically, I wrote a static methods that is accepting any string of arrays; however, it returns an array of integers. Whenever I pass an string of arrays, I am not getting expected out put.

Someone please advice.


This shouldn't even compile. myLengths() is defined as returning an int but you return 'y' which is an array of ints.
You have to define the method as returning int[] if that's really what you want.
You need to be clearer on what the code is supposed to do, with out a description we can only guess based on the code.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Jun wrote:Basically, I wrote a static methods that is accepting any string of arrays;

I don't want to pre-empt your book, but don't get too used to writing static methods, because when you start creating classes to do things, you'll probably want to write instance methods (no static qualifier) for them.

In this case it's fine because the method is entirely self-contained - ie, it doesn't need anything from "outside" (other than its parameter) to do its job - but you'll find later on that this often isn't the case.

HIH

Winston

PS: Welcome to JavaRanch!
 
Fred Kleinschmidt
Bartender
Posts: 572
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, I wrote a static methods that is accepting any string of arrays

No, it takes an array of strings.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!