Siddharth Bhatt
Siddharth Bhatt

Reputation: 5

Java character comparison error

char studentClass=(char)(br.read());        
if((studentClass>='1' && sudentClass<='10')) 

I want the program to proceed only if the value entered by the user is between 1 to 10, both inclusive. When I tried the above code, I am getting an error saying 'unclosed character literal' when I have enclosed both 1 and 10 in single quotes.

Upvotes: 0

Views: 65

Answers (2)

sujithvm
sujithvm

Reputation: 2411

10 is not a single character. You might want this

int studentClass=Integer.parseInt(br.readLine());        
if((studentClass>=1 && sudentClass<=10)) 

Upvotes: 2

Juvanis
Juvanis

Reputation: 25950

'10' is not a character. It is a set of characters. I wonder why you don't use integers:

int studentClass = Integer.valueOf(br.readLine());        
if(studentClass >= 1 && studentClass <= 10) 
{
  ...
}

Upvotes: 0

Related Questions