![]() |
return statement in java
hi all, i need help in using a java "return statement" to return: a fullName, a firstName, lastName and initials with lastName.
what i have done so far: public class ReturnAllValues { public static void main(String [] args) { String name = "Faith Hill"; } public String getName() { return name; } } the program compiles fine but does not return the value of "name". what am i doing wrong? what must i do to return all the values? your assitance is great appreciated. thank you! |
i'm not quite sure how it is suppose to return anything when you don't even call the function...
Code:
public class ReturnAllValuesand what do you mean by 'return all the values'? |
Thank you very much Deloch. I meant values such as first initials and lastname. for example: F. Hill.
Also, how can I create a string to hold multiple values in a single parameter and call those values individually with a return statement? for example: String name = new String ("Frank Herbert", "Mary Kolly", "Mike Polisi"); then call each name with a return statement. Again, thank you very much! Deloch, i ran the code in jCreator and it coughed up the following error message: "non-static method getName() cannot be referenced from a static context" The strange thing is that getName() method is under main so i don't understand why it's coughing up this error message. |
Quote:
http://java.sun.com/docs/books/tutor...ts/arrays.html and the return would be: Code:
return name[3] |
Quote:
make the geName() method static, and error will go away. |
simple arraylist usage
Code:
import java.util.ArrayList; |
'Mutley' I don't understand, what you are trying to explain. is it relevant to this thread?
This thread is no longer active. |
ch4sethe5un mentioned arrays. I thought it was worth the example.
|
| All times are GMT +1. The time now is 01:29 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.