0

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; 


}
}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by stultuske
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).

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.