Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# simple doubt on char

kiran vydhyam
Greenhorn
Posts: 7
when I declare chars,ex: char c=1; ,is it not neccessary that I quote the value with single quotes whether the value is an integer or a letter.
char c='1';
char c=1;
what is the differce here.

Marilyn de Queiroz
Sheriff
Posts: 9067
12
I suggest you try writing a tiny program that sets char c1='1' and char c2 = 1 and then does a Systen.out.println( "c1 = " + c1 + " c2 = " + c2 ) and let us know the results.
[ July 22, 2004: Message edited by: Marilyn de Queiroz ]

Dirk Schreckmann
Sheriff
Posts: 7023
As a slightly tangential note, I reference http://www.asciitable.com when I'm curious for the occasional ASCII (character) value.

Ripan Karmakar
Greenhorn
Posts: 16
Source Code:
public class Char
{
public static void main(String args[])
{
char c1=1;
char c2='1';

System.out.println("c1=" + c1 + " and " + "c2=" + c2 ) ;
}
}

o/p: c1=☺ and c2=1

that means: 1st one gives the ASCII Value of 1
2nd one gives the value as within ' '

Ranch Hand
Posts: 382
Originally posted by Ripan karmakar:
Source Code:
public class Char
{
public static void main(String args[])
{
char c1=1;
char c2='1';

System.out.println("c1=" + c1 + " and " + "c2=" + c2 ) ;
}
}

o/p: c1=☺ and c2=1

that means: 1st one gives the ASCII Value of 1
2nd one gives the value as within ' '

Bummer, man. You robbed the OP of finding this out himself/herself.
[ July 29, 2004: Message edited by: Sadanand Murthy ]