aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java primitive problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java primitive problem" Watch "java primitive problem" New topic
Author

java primitive problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634



output:
115
115
s
ssks

why is the second print statement displaying 115 ?
shouldn't be the output s as in case of third print statement.


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

The + before c in that expression represents the unary operator + which makes its operand c an int...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

mohitkumar gupta wrote:

output:
115
115
s
ssks
why is the second print statement displaying 115 ?
shouldn't be the output s as in case of third print statement.


Numeric promotion with unary operators(+,-,and ~)

The evaluation of the expression +c will first promote the value c to int and then apply the operator + resulting in an int value. This will also apply to char, short, byte...


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
 
subject: java primitive problem