#Determining character type

49 messages · Page 1 of 1 (latest)

dawn dagger
#
1. String methods
2. Array

This is the problem. How am i supposed to solve it? Isn't there any other way to do it without writing 50+ if - else if statements to do it?

thick spadeBOT
#

This post has been reserved for your question.

Hey @dawn dagger! Please use /close or the Close Post button 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.

rigid sparrow
#

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

dawn dagger
#

what about special characters?

rigid sparrow
#

for all we know, special characters are just outside of the range of everything else we can classify

dawn dagger
#

that means, if i can satisfy that the character is not alphaneumeric and not a number, then its a special character right? @rigid sparrow

rigid sparrow
#

yes

#

probably

dawn dagger
#

w8

#

lemmi see if it works

#

how can i check if it is a number?

#

does character == int.class work???

#

@rigid sparrow

rigid sparrow
dawn dagger
#

uh, then?

rigid sparrow
#

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

dawn dagger
#

okay, but now i am stuck in another problem...

#

which method is used to take char as input?

#

from the scanner class?

rigid sparrow
#

try scanner.next(".").charAt(0)

#

or just scanner.nextLine().charAt(0)

dawn dagger
#

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

rigid sparrow
#

well you do need a character to check

dawn dagger
#

yeah

rigid sparrow
#

you need to make the scanner first before using it

dawn dagger
#

you mean the scanner object?

rigid sparrow
#
Scanner scanner = new Scanner(System.in);
char character = scanner.nextLine().charAt(0);
dawn dagger
#

yeah

#

finally it worked...

#

thank you very much @rigid sparrow

thick spadeBOT
# dawn dagger thank you very much <@1067125865785344031>

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.