hi there, im very new to programming and i have trouble coding a application that prompts the user for s series of first names and then display the number of names entered and then the name with the most characters in uppercase letters. the application output should look similar to this:

Enter a first name (stop to quit): John
Enter a first name (stop to quit): Andrew
Enter a first name (stop to quit): Robert
Enter a first name (stop to quit): Lisa
Enter a first name (stop to quit): Emilios
5 names were entered.
The longest name was: Emillios

i've come this far

import java.util.*;
import java.util.Scanner

public class LongestName
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
int counter = 0; 


}
}

Well. You should start by looping around to ask for inputs. This might look like this:

String lastInput;

while(lastInput.equals(/*Some string that means to stop asking for input*/)
{
System.out.println("Enter a first name. Enter '0' for stop.");
lastInput = input.getLine();
if(lastInput.equals(/*Some string that means to stop asking for input*/)
break;
}

I'm going to leave some of it up to you, such as putting the name that you take in storage, and how to find the longest, etc name among the group (HINT: Use the String Classes' methods).

if you do use this approach, I would recommend you to initialise lastInput as

String lastInput = "";

otherwise, it's a nullpointerexception in the making. an approach I would recommend, is entering the first name before you enter the loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.