initialization - I am confused about the data types of java. -


यह क्यों सही है?

  char c1 = 125;   

और यह क्यों गलत है?

  चार सी 2 = सी 1 + 1;   

ऊपर दिए गए कोड का सही तरीका होना चाहिए:

  चार सी 2 = (चार) (सी 1 + 1);   

मैं उलझन में हूँ बहुत बहुत धन्यवाद!

यह गलत है क्योंकि char पूर्णांक 1 में c1 को c1 को int में जोड़ा जाता है। जब आप इसे char java शिकायत में वापस डालते हैं, क्योंकि यह वादा नहीं कर सकता कि int एक char में फिट होगा >

-एडिट -

char c = 123 के मामले में 123 भाग ज्ञात है, इसलिए जावा वास्तव में यह वादा कर सकता है कि यह हमेशा एक char में फ़िट होता है यह भी काम करेगा:

  अंतिम चार c0 = 123; चार सी 1 = सी 0 + 1;   

और यह:

  अंतिम अंत i0 = 123; Char c1 = i0 + 1;    

Comments

Popular posts from this blog

c# - The item with identity 'Id' already exists in the metadata collection. Parameter name: item -

sql - PostgreSQL automatically update row at specific date -

jsp - No mapping found for HTTP request with URI with annotation config Spring MVC and Jetty -