• Register
0 votes

I wrote a program like this 

 Scanner in = new Scanner(System.in);
   System.out.println("Input a letter"); 
   String line = in.nextLine();
   char c = line.charAt(0);
   if( character.isDigit(c))
   System.out.println(c +" Is a digit");
   else if (character.isLetter(c))
   System.out.println(c +" Is a Letter");

And It gives me error.

How can I solve this problem?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes

In your program you declared Character as character .
You should have programmed like below:

if (Character.isdigit(c)){
 System.out.println(c +" Is a digit");
else if (Character.isdigit(c)){
 System.out.println(c +" Is a digit");

You can also try this:

     System.out.println("Enter the value");
        String data;
        data = in.next();

        int len = data.length();
        for (int i = 0 ; i < len ; i++){
            char ch = data.charAt(i);

            if ((ch >= '0' && ch <= '9')){
                System.out.println("Number ");
            else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')){


11 6 4
34,950 points

Related questions

0 votes
1 answer 5 views
Problem: Hello! I am trying to write a program that takes input from the user and determines whether the user entered a number, alphabet, or a special character. I am a beginner so, facing some difficulty in understanding the logic. Can somebody from here help me find out the solution? Thanks!
asked 3 days ago Code Learner 6k points
0 votes
1 answer 24 views
Problem: The above formula is derived from shoelace formula. So we will check if the area formed by the triangle is zero or not. Below is the implementation of the above approach Java
asked Dec 2, 2020 Mashhoodch 9.3k points
1 vote
1 answer 265 views
Problem: I am looking for a solution to my existing code. Well, I am a new student of java. I was thinking about a program that can check whether the given char is an upper case or not! Let&rsquo;s say I&rsquo;ve given a char as &lsquo;a&rsquo; and I want ... , my question is, how to check whether a char variable ch is an uppercase letter, you write? Thanks for your valuable time and effort guys.
asked Mar 22, 2020 Gavin 15.3k points
0 votes
1 answer 35 views
I am very new at java programing, I have an assginment where I have to check if a character is uppercase in java and I wrote a code: public static void main(String[] args) { int A; char a = A; if (Character.isUpperCase()) { System.out.println(a + " is an uppercase character."); } } But it doesn&rsquo;t work how. Can anyone help me out?
asked Mar 15, 2020 LizzyM 6.1k points
0 votes
1 answer 22 views
I was doing my java programming practice. I wrote a code to check if a charcter is a number: public static void main(String[] args) { String string = "-1234.15"; String numeric ; numeric = string.matches("-?\\d+(\\.\\d+)?"); if(numeric) System.out.println(string + " is a number"); else System.out.println(string + " is not a number"); } But it gives me error. Whats wrong in my code?
asked Mar 15, 2020 LizzyM 6.1k points
0 votes
1 answer 9 views
Problem: Hi! I am a beginner and got stuck on an assignment in which I am asked to write a python function that takes three arguments and after performing some calculation, should tell whether the three values can be used to create a triangle. I am unable to build the logic. Please help!
asked 3 days ago Code Learner 6k points
1 vote
1 answer 17 views
Problem: To check whether the input is Floating point number or not in python I wrote this program: import re # check Floating point number def checked(floatnum): # pass the regular expression # and the string in search() method if(re.search(floatnum)): print( ... line 9, in checked if(re.search(floatnum)): TypeError: search() missing 1 required positional argument: 'string' Can anyone solve this?
asked Apr 28, 2020 samhaz 5k points
0 votes
1 answer 15 views
How can I do this?
asked Jan 19 TeamScript 13.5k points