1 Attachment(s)
Need a non void method to return the first three characters of a string
Trying to get a non void method to return the first 3 letters of a word but get the following error corresponding to the error in the attachment
"Type mismatch: cannot convert from int to string"
Re: Need a non void method to return the first three characters of a string
Can I suggest looking at this page and reading some of the methods etc.
String (Java 2 Platform SE v1.4.2)
Chris
Re: Need a non void method to return the first three characters of a string
Thanks Freaky Chris.
That link lead me to solving my problem.
In case anyone was curious to the solution:
Code java:
//Programming Projects 9.1
public class PP9_1
{
//Return the first three letters of the String Kris
public static String firstThreeInitials (String name)
{
String c = name.substring(0,3);
return c;
}
public static void main(String[] args)
{
String firstThreeInitials = firstThreeInitials("Kris");
System.out.println(firstThreeInitials);
}
}
Re: Need a non void method to return the first three characters of a string
You could pass them by reference instead.
Re: Need a non void method to return the first three characters of a string