Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java: Programming: Initials 1

Name ________________________________________

Write a program that asks for names and displays the initials.

  1. Ask the user for their first name. Save it in a string variable.
  2. Ask the user for their last name. Save it in a string variable.
  3. Use the substring() method to get the first characters from both the first and last names. Use the toUpperCase() method to convert them to upper case.
  4. Display the initials to the user.

Discussion

What you need is the first letter of each name. There are two ways to get it.

  1. substring(...). You can use the substring(...) method to get a one-character substring starting at the beginning of the name. You can then concatenate this to the first letter from the other name.
  2. charAt(...) Strings are made up of characters (primitive type char). You can extract the first character with charAt(...) and proceed pretty much as above.

Which to use? They are both reasonable solutions. If you were doing a huge amount of computation -- processing hundreds of thousands of names, it would be more efficient to use the charAt(...) solution because it's more efficient to use a primitive type than an object type. On the other hand, the substring(...) solution has the simplicity of working with only one type (String). Use either one.

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.