i have to create a city application that prompts the user for a series of city names and then displays the number of city names entered and then the name of the city with the most characters in uppercase letters.
how come it always output the last name entered ?
import java.util.Scanner;
public class Cities
{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
int maxLength = 0;
int length = 0;
int count = 0;
String longName = "";
System.out.print("Enter a city name <stop to quit> :");
String name = input.nextLine();
while(!(name.equals("stop")))
{
length = name.length();
if(length> maxLength)
longName = name;
System.out.print("Enter another city name <stop to quit> :");
name = input.next();
count++;
}
System.out.println(count + " were entered" );
System.out.println("The longest was : " + longName);
}