Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

15.2: Comparing Characters Write a program that tests if the first or last letter of a word is earlier in the alphabet. If the characters

15.2: Comparing Characters

  • Write a program that tests if the first or last letter of a word is earlier in the alphabet.
  • If the characters are the same, we will note that as well.
  • Recall that we may compare String characters to each other because they are stored as numbers in the computer, according to a standard known as Unicode.
  • Name the project FirstLast with a class called FirstLast.java and include all your code in this single file.
  • Ask the user for the following inputs (and no other input) in this order and each on their own line:
    1. a word such as "easy" (without the quote marks) as a String
    2. "y" or "n" (without the quote marks) to see if the program should loop again
    • Assume the user enters only valid data.
    • See sample output below
  • Use the substring method that we learned in Lesson 14 to extract the first and last characters, and then test if the first or last letter of the word is earlier in the alphabet.
    • Do NOT use charAt() or you will not receive credit for this assignment. You must use substring() to access the first and last characters.
  • Note the use of "" around the letter in the output below. These must be included.
  • If the letters are the same then print, "Letters are the same." (without the quotes) as shown in the sample output.
  • Add a while statement that allows the user to repeat the program by inputting a "y" (without the quotes), and exiting the loop for any other character entered, as shown in the sample output.
  • When your program works identically to the example output below, submit it to Canvas:

Your output should look identical to the output below:

***Comparing First and Last Characters*** Input a word: easy First letter "e" is earlier in the alphabet. Run again? (y/n) y Input a word: zebra Last letter "a" is earlier in the alphabet. Run again? (y/n) y Input a word: Zebra First letter "Z" is earlier in the alphabet. Run again? (y/n) y Input a word: eve Letters are the same. Run again? (y/n) n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

Explain the importance of nonverbal messages.

Answered: 1 week ago

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

Prepare an employment application.

Answered: 1 week ago