Concept explainers
Explanation of Solution
Program:
//define the static function
public static void longestName(Scanner console, int names) {
//print statement
System.out.print("name #1? ");
//The user input is stored in "longest"
String longest = console.next();
//declare and initialize the variables
int count = 1;
//loop initialized to determine the maximum value
for (int i = 2; i <= names; i++) {
//print statement
System.out.print("name #" + i + "? ");
//The user input is stored in "name"
String name = console.next();
//condition initialized to check whether the length of name is longest or not
if (name.length() == longest.length()) {
//increment the value
count++;
}
//condition initialized to check whether the value of next is greater than the length of longest or not
if (name.length() > longest...
Trending nowThis is a popular solution!
Chapter 4 Solutions
EBK BUILDING JAVA PROGRAMS
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education