Question

Write a Java class that examines a single character input from the keyboard. Follow this dialog...

Write a Java class that examines a single character input from the keyboard. Follow this dialog to guide your coding:

Type a single character and press Enter: m

Digit: No
Letter: Yes
Lowercase: Yes
Toggle case: M

Note: There is no "next" method of the Scanner class to obtain input from the keyboard of data type char. It simply doesn't exist so you need a workaround. Store the end-user input into a String variable; then extract the first character using the appropriate String class method (see the chart in Notes 4). Assign the resulting character to a variable of type char and use it for the remainder of the solution.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of the code with comments:

Sample output:

For input character 'm'

Source code:

import java.util.Scanner;

public class HelloWorld{
  
public static void main(String []args){

Scanner sc=new Scanner(System.in);

// Accepting a character from the user
System.out.println("Type a single character and press Enter: ");
String str=sc.next();
char ch=str.charAt(0);

// Check if the character is a digit
if(Character.isDigit(ch))
System.out.println("Digit: Yes");

// If not, proceed to check if it is a letter
else
System.out.println("Digit: No");
  
if(Character.isLetter(ch))
{ System.out.println("Letter: Yes");
System.out.print("Lowercase: ");

// Check if the character is lowercase and toggle it
if(Character.isLowerCase(ch))
{ System.out.println("Yes");
System.out.print("Toggle case :");
System.out.println(Character.toUpperCase(ch));
}
  
// If not display NO and toggle it
else
{
System.out.println("No");
System.out.print("Toggle case :");
System.out.println(Character.toLowerCase(ch));
}
}
  
}
}

Add a comment
Know the answer?
Add Answer to:
Write a Java class that examines a single character input from the keyboard. Follow this dialog...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • The Scanner class in Java has several methods for reading values entered from the keyboard. The...

    The Scanner class in Java has several methods for reading values entered from the keyboard. The methods include next, nextInt, and nextLine. Which of the following statements is INCORRECT about the methods? Pick the best applicable answer Assuming that the user has typed: Hello World! If you invoke the next method for the first time, it will return the string "Hello", and if you invoked next method for the second time, it will return the string "World!" If you want...

  • Solve it by JAVA please. Now, write a class named InputSplitter. This class will take input...

    Solve it by JAVA please. Now, write a class named InputSplitter. This class will take input from the keyboard (using a Scanner) and split the incoming tokens into integers, floating point numbers, and strings. The incoming tokens will be added to one of three accumulators which start out at zero, and which keep a running total. Thus, the class will have an accumulator for integers. It starts out with the value zero. Every time another integer is read in, it...

  • Please USE JAVA only Write a class named InputSplitter. This class will take input from the...

    Please USE JAVA only Write a class named InputSplitter. This class will take input from the keyboard (using a Scanner) and split the incoming tokens into integers, floating point numbers, and strings. The incoming tokens will be added to one of three accumulators which start out at zero, and which keep a running total. Thus, the class will have an accumulator for integers. It starts out with the value zero. Every time another integer is read in, it is added...

  • A class Scanner in Java can be used to get user input and its methods can...

    A class Scanner in Java can be used to get user input and its methods can be used after the following statement is executed: Scanner input = new Scanner(System.in); One of its methods nextDouble() returns the next double value from the keyboard. Now you are requested to write a method enterHeight() which displays the message "Input height: " and uses the method input.nextDouble() to get the user input. The process should be repeated until the input is non-negative. Finally the...

  • (a) A class Scanner in Java can be used to get user input and its methods...

    (a) A class Scanner in Java can be used to get user input and its methods can be used after the following statement is executed: Scanner input = new Scanner(System.in); One of its methods nextDouble() returns the next double value from the keyboard. Now you are requested to write a method enterHeight() which displays the message "Input height: " and uses the method input.nextDouble() to get the user input. The process should be repeated until the input is non-negative. Finally...

  • Java Switch Case Make From Pseudocode

    The following pseudo-code describes a menu-driven algorithm:loopask the user to input one of the characters a, b, c, d, e, q read in a character from the keyboardif the character is'a' output your name and your tutor's name (hard-coded) 'b' input 3 double numbers x, y, z and output the largestand the smallest of the three numbers'c' input 2 integer numbers m and n, and display all thenumbers between m and n (both inclusive) with five numbers per line (note...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Create a Java program Named LB04 with a class name HardMonogram Input:   fullName Process: getInitial(separateName): extract the...

    Create a Java program Named LB04 with a class name HardMonogram Input:   fullName Process: getInitial(separateName): extract the first character string from each part of a full name and return it. getSeparateName(fullName): separate a full name into first name, middle name, and last name. setMonogram(): using getInitial(), generate the right monogram result, then display it. main(String[] args): driver method Output: - Using JOptionPane to get a first name, middle name, and last name at once, then, on a JOptionPane dialog, show the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT