#Determining character type
49 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @dawn dagger! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
well there's this thing called ascii ranges
your character is just an integer at the end of it, you can check if the character is in a specific range to classify it
with that last statement, you can effectively check if character T is between A and Z
what about special characters?
did the problem define what special characters are
for all we know, special characters are just outside of the range of everything else we can classify
nah
then its probably this
that means, if i can satisfy that the character is not alphaneumeric and not a number, then its a special character right? @rigid sparrow
w8
lemmi see if it works
how can i check if it is a number?
does character == int.class work???
@rigid sparrow
no
uh, then?
use this
character >= '0' && character <= '9'
just put your own values in it
as mentioned, each character has an id attached to it
like you can see in that screenshot
eg 0 has id 48, / has id 47, etc
and since the devs of that standard were smart enough to put related characters together, you can basically check if a character is of a specific type just by looking if its in the right range or not
you gotta be careful with letters tho, upper and lowercase letters have different ranges
okay, but now i am stuck in another problem...
which method is used to take char as input?
from the scanner class?
CharacterDeterminant.java:7: error: non-static method nextLine() cannot be referenced from a static context
char character = Scanner.nextLine().charAt(0);
^
1 error
error: compilation failed
it returned this
w8
i don;t need a character, i can simply use string
nah i have to use character
well you do need a character to check
yeah
you need to make the scanner first before using it
you mean the scanner object?
Scanner scanner = new Scanner(System.in);
char character = scanner.nextLine().charAt(0);
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.