• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char doubt

 
Syed Naimathullah
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is giving compile time error at line 1,5

class MCZ11 {
public static void main (String[] args) {
char a = '\c'; //line 1
char b = '\r';
char c = '\"';
char d = '\b';
char e = '\p'; //line 5
}}
please explain me why
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look for escap sequences in java.
 
anshi kohli
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
char range is 0-65535 verified with K&B book but pg 69 of khalid says its 0-65536(which is wrong i believe).

please correct if i m wrong?
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have go home to check pg 69. Still I can vote for 0-65535 range today. Will be back here tomorrow.
 
Hasan Moulana
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

char a = '\c'; //line 1
char b = '\r';
char c = '\"';
char d = '\b';
char e = '\p'; //line 5

why we use \ inside the quotes is to the characters ', ", ` and for backspace (\b), carriage return (\r) and line feed (\n).

I think (\p) does not mean any thing. thtsy it is throwing error.

char a = '\r'; //line 1
char b = '\b';
char c = '\"';
char d = 'b';
char e = 'p'; //line 5

if you execute this, it wont show the error.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following are common escape sequences in Java:
  • \b = backspace
  • \f = form feed
  • \n = new line
  • \r = return
  • \t = tab
  • \' = single-quote literal
  • \" = double-quote literal
  • \\ = backslash literal
  • And here's a memory device for remembering the first 5: "Big Farms Need Red Tractors." (\b, \f, \n, \r, \t)
    [ July 12, 2007: Message edited by: marc weber ]
     
    Priyam Srivastava
    Ranch Hand
    Posts: 169
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks Marc for that memory device !!!
     
    Akhilesh Trivedi
    Ranch Hand
    Posts: 1608
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by anshi kohli:
    char range is 0-65535 verified with K&B book but pg 69 of khalid says its 0-65536(which is wrong i believe).

    please correct if i m wrong?


    Hello anshi! me back here. My book titled A programmers guide to java certification by Khalid Mughal and Rolf. W. Rasmussen, second edition with Indian print coyrighted 2004, at page 29 says, second paragraph first line says... "Their values are unsigned integers that denote all the 65536(2^16) characters in the 16-bit unicode character set."

    So the actual set of characters is 65536, but when you say 'range', it actually starts with 0 and ends up with one minus of the total... cho chimple right. have fun.
     
    Jared Folino
    Greenhorn
    Posts: 25
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    A good accronym is
    farms
    nneed
    big
    red
    tractors
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic