Click to See Complete Forum and Search --> : Returning
B-80
June 5th, 2005, 03:32 PM
Ive been java programming for about a year now, and ive always sporaticly had problems returning from classes ill give you an example
public class Search
{
Search()
{
}
public int split(String string1, int integer, String search)
{
String[] array;
array = string1.split(search);
integer = array.length -1;
return integer;
}
}
its very simple, and it gets the right answer, but it wont return the "integer" variable, any ideas why
kaaj
June 6th, 2005, 06:01 AM
Try accessing the the split method in Search class using its own instance as shown below :
Method 1 :
Search s = new Search();
int i = s.split("Nature Calls me", 10, "Call");
System.out.println(" Output : ", i);
Method 2 :
If u have confusion in method name 'split' rename to anything else..
since u might confuse it with String.split(args)
cjard
June 6th, 2005, 01:27 PM
Ive been java programming for about a year now, and ive always sporaticly had problems returning from classes ill give you an example
public class Search
{
Search()
{
}
public int split(String string1, int integer, String search)
{
String[] array;
array = string1.split(search);
integer = array.length -1;
return integer;
}
}
its very simple, and it gets the right answer, but it wont return the "integer" variable, any ideas why
what do you mean "wont return" the variable.. what are you hoping it will return?
for methods of searching strings, see here:
http://javaalmanac.com/egs/java.lang/HasSubstr.html
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.