Need help...newbie to Java Programming

Joined
Sep 22, 2010
Messages
1
Reaction score
0
My teacher wants us to create the following program:

Ask user to enter: First Name, Middle Name, Last Name

Output: FName_Initial MName_Initial, Last Name

And Length of the Input string.

Example:

User Input: Helen Jane Brown

Output: String Length: 16 Characters

User Name: H J Brown


The teacher wants us to use indexOf to show the length of the output once the user inputs their entire name...i have no clue how to do that, or how to show the adding up of the characters since each input is typed in differently, meaning. the user will input first name, then middle name, then last name; so how do u create a string or int to add up 3 different strings?
im soooo lost....below is wut i came up with, but of course it has a lot of errors. thanks for any help



import java.util.*;
public class FMLast
{
static Scanner console = new Scanner(System.in);
public static void main (String[] args)
{

String lastName = "";
String middleName = "";
String firstName = "";
int index1;
int index2;
int index3;
int length;

index1 = firstName.indexof(" ");
index2 = lastName.indexof(" ");
index3 = middleName.indexof(" ");

length = index1 + index2 + index3;




System.out.print("Enter your first name: ");
firstName = console.next();

System.out.print("Enter your middle name: ");
middleName = console.next();

System.out.print("Enter your last name: ");
lastName = console.next();

System.out.println("User Output: " + firstName + " " + middleName + " " + lastName);
System.out.println("Output: String Length: " + length + " Characters");
System.out.println("User Name: " + firstName.charAt(0) + " " + middleName.charAt(0) + " " + lastName);




}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,184
Members
46,721
Latest member
DollieSawt

Latest Threads

Top