Using loops, and not arrays, design a Java program that asks the user for a series of names (in no particular order). After the final person's name has been entered, the program shold display the name that is first alphabetically and the name that is last alphabetically. For example, if the user enters the names Kristin, Joel, Beth, Zeb, and Chris, the program would display Adam and Zeb.
Program
import java.util.Scanner;
public class FirstandLastNames
{
public static void main(String[] args)
{
Scanner SC=new
Scanner(System.in);
String
name,low="",high="";
System.out.print("Please
enter a name(Enter q to stop):");
name=SC.next();
if(!name.equals("q"))
{
low = name;
high = name;
}
while(!name.equals("q"))
{
System.out.print("Please
enter a name: ");
name=SC.next();
int x;
x =
name.compareToIgnoreCase(low);
if(x<0)
{
low = name;
}
x =
name.compareToIgnoreCase(high);
if(x >0)
{
high = name;
}
}
System.out.println("First name :"+low);
System.out.println("Last
name :"+high);
}
}
Output
Please enter a name(Enter q to stop):Kristin
Please enter a name: Joel
Please enter a name: Adam
Please enter a name: Beth
Please enter a name: Zeb
Please enter a name: Chris
Please enter a name: q
First name :Adam
Last name :Zeb
Using loops, and not arrays, design a Java program that asks the user for a series...