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"
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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"
Can I suggest looking at this page and reading some of the methods etc.
String (Java 2 Platform SE v1.4.2)
Chris
Thanks Freaky Chris.
That link lead me to solving my problem.
In case anyone was curious to the solution:
//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); } }
Last edited by Freaky Chris; November 9th, 2011 at 07:41 AM. Reason: Added syntax
You could pass them by reference instead.
Java is pass-by-value!
Improving the world one idiot at a time!