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 basically already did that, just need to create a new method // this given method returns a string consisting only of initials of the given name public String initials(String Firstname,String lastName){ return ""+Firstname.charAt(0) + lastName.charAt(0); } then call it in your main : public static void main(String args[]){ String first = "Abe"; String second="Lincoln"; System.out.println("initials of "+ first + second + " are " + initials(first,second)); } Hope this helps!

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

Was this solution helpful to you?

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.