• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic