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
Related Q & A:
- How can I convert a string number to a number in Perl?Best solution by Stack Overflow
- How do I split a String and keep the delimiters?Best solution by Stack Overflow
- How do I make a call from Canada to the UK?Best solution by Yahoo! Answers
- How can I make a phone call to a cruise ship?Best solution by traveltips.usatoday.com
- How do I call a cell phone in Australia?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.