क्या आप कृपया बता सकते हैं कि पिछले 2 प्रिंट स्टेटमेंट में क्या चल रहा है? यही वह जगह है जहां मैं हार गया।मैं तीसरे और चौथे प्रिंट स्टेटमेंट में वर्णों के बजाय पूर्णांक क्यों लौटा रहा हूं?
public class Something
{
public static void main(String[] args){
char whatever = '\u0041';
System.out.println('\u0041'); //prints A as expected
System.out.println(++whatever); //prints B as expected
System.out.println('\u0041' + 1); //prints 66 I understand the unicode of 1 adds up the
//unicode representing 66 but why am I even returning an integer when in the previous statement I returned a char?
System.out.println('\u0041' + 'A'); //prints 130 I just wanted to show that adding an
//integer to the unicode in the previous print statement is not implicit casting because
//here I add a char which does not implicitly cast char on the returned value
}
}
चूंकि 'char' को 'int' के रूप में डाला जाता है। यदि आप मूल्यों को जोड़ना चाहते हैं, तो उन्हें 'स्ट्रिंग' में बदल दें। –
char से int में रूपांतरण जावा में निहित है। –
Charecters पूर्णांक के अलावा कुछ भी नहीं हैं। – eatSleepCode