How do I call an objective-c method?

How do i call a string method in main?

  • I was given instruction as follow: String inintials( String first, String last): this mothod should return a String that consist of of the first letter of the first formal parameter, first, and the first lettter of the second formal parameter, last. For example, if first = "Abe", and last = "Lincoln", then this method should return the String, "AL. This method should be displayed by main as: "Initials of Abe Lincoln is AL" Ok, I understand what it asking for, but i don't know how tell main to call method. I know how do it in main, like: public static void main(String[] args){ String first = "Abe"; String last = "Lincoln"; System.out.println("Initials of Abe Lincoln is first.charAt(0) + last.charAt(0)); } But i'm not supposed to do so. I'm supposed to create a method as given in the instruction, and then tell main to do it, and I don't know the syntax for calling this method.

  • Answer:

    You need to write the method before you can invoke it. You've posted this question just a few minutes ago. Most of us here think that to do your assignment for you hurts more than helps you. Try to write the code to do it and then post the code if you need more help.

â—„Ferroci... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

So, what the other guy said is sensible... And while I'm no code wizard and, in fact, don't even know for sure what language your using, here are some key things to understand that should apply accross the board... main() is a method. So you're defining a method there. So to make another one, you just... do that again. So instead of just having main(), you'll have main() and whatever other method. The second piece to consider is that, to my knowledge, the difference between a method and a function is that a function returns a value, so you can say "X = function(arguement);", while a method just takes your arguements and does stuff, so you can say "method(arguement);". Since the function returns a value, it has a type and a return() statement. The method is typed "void" so that it doesn't require a return statement. There might be a MORE correct definition of method vs function per all the computer science types out there, but that seems to about sum it up. To further cement the point, System.out.println(), in this instance, is behaving as a method.

William

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.