Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Terenary operator

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pl. suggest :
The problem is with terenaray operator.When I am putting
66 as value-1 & '65' as value-2 ,I am getting comp.'n error saying
invalid character constant, whereas if I am putting '6' as value-2,
it get compiled.
class Operator31
{
public static void main(String[] args)
{
int x=1;
// Lna:System.out.println((x>3 )?66:'65');//compErr:Invalid
//character constant.-'65'
Lnb: System.out.println((x>3 )?66:'6');
//compiling (x>3?66:'6');o/p=6.
}
}// end of class Opeartor31
I am clueless. . .
Thanks,
Vikas
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
were u expecting an 'A' there?
'65' is not a valid character. if u say char c = 65; it is valid and will print an 'A' because the integer value 65 represents 'A'. in single quotes u can have a single character. 65 is not a character.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This can be expalined as,
char c1 = '65'; //invalid
char c2 ='6'; //valid
char only takes unicode datatype, '65' is not basic character in Unicode (or ASCII) character set. It is combination of to charcters '6' and '5' so it gives error.
char c1 = 65; Same can be represented as,
char c1 ='A';
char c1 ='\u0041'; //hex equivalent of decimal 65

 
vikas singh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx sweekriti & sujit,
could you pl. further provide me some links from where
i can get details about unicode & ascii.
regards,
vikas
 
crispy bacon. crispy tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic