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

can someone tell me what is the means of ' ' ?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class q2
{
public static void main(String args[])
{

System.out.println(4+" "+2);
System.out.println(4+' '+2);
}
}

---
the result is
4 2
38 <--- i don't know why???
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
' ' is interpreted as a white space character, whose value is 32 (0x0020)

So 4 + 32 + 2 = 38
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mauriace Sendak,

Welcome to JavaRanch! Is this your real name? We have a policy at JavaRanch that everyone should use their real name, we've found it keeps things friendlier!

So, in case this isn't your real name I'd like to ask you to change it!

Thanks,

Bert
 
Shiao Kung Chux
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ,

i agree your name rule.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding Shiao's question, Some more points.

The white space is interpreted as a number because since the other values in the group are int's, the char is also upcasted to int.

But in a different case like -->System.out.println(" "+4+' '+2)<---, you will get the output as 4 2 and not 38. This is because, the first value is a String, so all other values are implicitly converted to String.

If it is --->System.out.println(4+' '+2+" ")<----, then the output will be 38 and not 4 2. This is because, only after evaluating the values, the String appears. So the convertion takes places only after the evaluation.
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic