• Register
0 votes
39 views


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')){
            System.out.println("Character");
            }
            else{
                System.out.println("Symbol");
             }
        }

 

11 6 4
34,950 points

Related questions

0 votes
1 answer 26 views
26 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 Feb 25 Code Learner 9.8k points
0 votes
1 answer 8 views
8 views
Problem: I tried by past 1 Week to short out from this problem, but j can't able to, that's why I am posting here if anyone know it's answer then please answer me.
asked Apr 3 niyatiry 3.9k points
0 votes
1 answer 13 views
13 views
Problem: I use minify for both css and js via the W3 Total Cache plugin. In W3C validator I get: *Error: The character encoding was not declared. Proceeding using windows-1252
asked Apr 21 ummesalma 29.2k points
0 votes
1 answer 12 views
12 views
Problem: how to print ascii characters in java. help me in solving this problem.
asked Mar 13 Dan phillip 4.8k points
0 votes
1 answer 2 views
2 views
Problem: I need someone&rsquo;s help to fix it .. how to do a smiley face on word
asked Apr 7 Ifra 36.4k points
0 votes
1 answer 3 views
3 views
Problem: Does anyone know the solution of it? So kindly let me know .. how to do a smiley face in word
asked Apr 7 Ifra 36.4k points
0 votes
1 answer 2 views
2 views
Problem: Please help me &hellip; how can I solve it? how to make a smiley face in word
asked Apr 7 Ifra 36.4k points
0 votes
1 answer 1 view
1 view
Problem: Can anyone please point me in the right direction > Write a program to check whether the given number is even or odd in c++
asked 1 day ago ummeshani 9.5k points
0 votes
1 answer 24 views
24 views
Problem: xml version= 1.0 encoding= utf-8
asked Mar 3 charles mathews 5.5k points