How to check if a user input is a char or a int
so yeah i got this problem. i have to do a program and the first part of it is user input.
i have 5 choices. 4 are an int and one is a char.
heres the code i got so far.
Code :
int reponse;
System.out.println("1-Plus longue repetition de nucleotide");
System.out.println("2-Liste des sous-sequences communes");
System.out.println("3-Plus longue sous-sequence communes");
System.out.println("4-Alignement optimal");
System.out.println("q-Quitter");
reponse = Keyboard.readInt();
System.out.println(reponse);
if (reponse == 1)
{
}
if (reponse == 2)
{
}
if (reponse == 3)
{
}
if (reponse == 4)
{
}
oh and btw the keyboard class is a class my teach gave me for my class cause we are complete beginners :P its basically used for user input.
so as you can see i did an if for all the int reponse but what about if the user enters q? how do i check it?
sorry if its in french but the code is still in english right.
looking forward to your help
Blackbird94
Re: How to check if a user input is a char or a int
http://www.asciitable.com/index/asciifull.gif
Answer is in the image really.
Look at the decimal values.
Re: How to check if a user input is a char or a int
dosent seem like java is giving any value to "reponse" when i enter q. I tried printing it out it just gives 0
Re: How to check if a user input is a char or a int
What errors are you getting? What did you try to solve the issue? What should It be doing?