Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

char doubt

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look for escap sequences in java.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
     
    Ranch Hand
    Posts: 169
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thanks Marc for that memory device !!!
     
    Akhilesh Trivedi
    Ranch Hand
    Posts: 1609
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Greenhorn
    Posts: 25
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    A good accronym is
    farms
    nneed
    big
    red
    tractors
     
    Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic