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

Write a program that reads a char as an input from the keyboard and outputs whet

ID: 3799543 • Letter: W

Question

Write a program that reads a char as an input from the keyboard and outputs whether it is a digit. (Hint: look for a method in the Character class.)

This is for my Java class, use if and else if statements for this program. If anyone can help that would be awesome! The output should look something like the following picture:

Problems Javadoc Declaration O Console 23 Kterminated DigitCheck Java Application] C:Program FilesUava jre1.8.0 111 binjavaw.exe Jan 3, 2017, 12:15:05 PM) Enter a character 1 h is a digit or if a letter is entered: Problems i Javadoc Q, Declaration Console >3 terminated DigitCheck Java Application] CAProgram FilesUavaVre1.8.0 111 binVavaw.exe (an 3r 2017, 12 15:40 PM) Enter a character a a is not a digit

Explanation / Answer

import java.util.Scanner;

public class InputTest {

  

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

      

       System.out.print("Enter a character > ");

       char c = sc.next().charAt(0);

      

       if(Character.isDigit(c))

           System.out.println(c+" is a digit");

       else

           System.out.println(c+" is not a digit");

   }

}

/*

Enter a character > a

a is not a digit

Enter a character > 5

5 is a digit

*/

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