Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Is it a Letter, Digit, or Something Else? Write a Java test program, all the code should be in a single main method, that prompts

Is it a Letter, Digit, or Something Else? Write a Java test program, all the code should be in a single main method, that prompts the user for a single character. Display a message indicating if the character is a letter (a..z or A..Z), a digit (0..9), or other. Java's Scanner class does not have a nextChar method. You can use next() or nextLine() to read the character entered by the user, but it is returned to you as a String. Since we are only interested in the first character, the character at position 0, you can use the following line of code to get just the first character out of the String returned by Scanner. char c = input.charAt(0); Unlike Strings, you can compare characters using relational operators. Recall that that the characters are in sequence; A comes before B, and B comes before C, etc. It's legal to write the following code in Java: if ( c > 'A' && c < 'Z' ) This tests to see if c is a capital letter. I envision your program working as follows: Sample Execution Enter a character: 1 You entered a digit. Sample Execution Enter a character: z You entered a letter. Please submit your .java file for grading Hint 1: Suggested Pseudocode get character from user is character a letter of the alphabet? print letter message otherwise is character a digit? print digit message otherwise print other type of character message

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_2

Step: 3

blur-text-image_3

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

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions