Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The letters of the English alphabet have an ordering, from \'a\' to \'z\'. When

ID: 3755780 • Letter: T

Question

The letters of the English alphabet have an ordering, from 'a' to 'z'. When we alphabetize names, we put the names in the order of the letters.

In this problem we are looking to find the character of the input string that comes the latest in this ordering. For instance, the letter 'z' comes last in the alphabet, so if 'z' is in the String it will be the latest-ordered character. If there is no 'z', then 'y' would be next, otherwise 'x', 'w' and so on backwards through the alphabet. (HINT: That was not a description of how to solve the problem)

Write code to read a line of text from the keyboard, find the latest-ordered character (treating all characters as lowercase), and print it out. Your code will be within the main() method inside a TextOrdering class in the file TextOrdering.java

Here are some sample I/Os:

Enter a line of text:

This is a long long long line of text.

Latest-ordered character is 'x'.

Enter a line of text:

NC A&T SU

Latest-ordered character is 'u'.

Explanation / Answer

Here is the code

..................................................................................

import java.util.Scanner;

public class TextOrdering

{

public static void main(String[] args)

{

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter a line of text:");

String userInput = keyboard.nextLine();

char[] stringToCharArray = userInput.toLowerCase().toCharArray();

char latest_char ='a';

for (char character : stringToCharArray){

if (character>latest_char) {

latest_char=character;

}

}

System.out.println("Latest-ordered character is '"+ latest_char+"'");

}

}

Same Output

..................................................................

Enter a line of text:
AWR35'fo1'35046052=1z
Latest-ordered character is 'z'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote