µ±Ç°Î»Ö㺠´úÂëÃÔ >> J2SE >> Long l=Ò»;Ϊʲôͨ²»¹ý
  Ïêϸ½â¾ö·½°¸

Long l=Ò»;Ϊʲôͨ²»¹ý

Èȶȣº422   ·¢²¼Ê±¼ä£º2016-04-23 22:24:59.0
Long l=1;Ϊʲôͨ²»¹ý£¿

class LongTest
{
public static void main(String[] args) 
{
Long l=1;
System.out.println("Hello World!");
}
}


±¨´íÐÅÏ¢£º
E:\code\java>javac LongTest.java
LongTest.java:5: ´íÎó: ²»¼æÈݵÄÀàÐÍ
                Long l=1;
                       ^
  ÐèÒª: Long
  ÕÒµ½:    int
1 ¸ö´íÎó

×î½üÔÚ¿´JAVA»ù´¡£¬ÆäʵÉÏÃæ˵µÃºÜÇå³þÁË£¬ÕûÊýÐÍĬÈÏÊÇint,longÐÍÖµºóÃæÒª¼ÓÉÏl»òL,java²Å»á°ÑËüµ±long
µ«ÊÇÎÒÏÖÔÚÉùÃ÷µÄ±äÁ¿¾ÍÊÇÒ»¸ölongÐ͵ģ¬Õ⻹²»Çå³þÂð£¿
Ϊʲô·ÇÒªÔÚÖµºóÃæ¼Ól?
long int ĬÈÏ

------½â¾ö·½°¸--------------------
longºÍLong²»Ò»Ñù£¬Èç¹ûÊÇlong l=1£»ÊÇûÓÐÎÊÌâµÄ£¬×Ô¶¯×ªÐÍint to long£¬µ«LongÊÇlongµÄ°ü×°Àà¡£
°ü×°ÀàµÄ×Ô¶¯×°ÏäÓë²ðÏäÖ»ÄÜÓë¶ÔÓ¦µÄ»ù±¾ÀàÐÍÖ®¼ä£¬»ù±¾ÀàÐÍÖ®¼äÒªÈ˹¤×ªÐÍ£¬ÄãµÄ¸ÄΪLong l=1l£»»òÕßLong l=(long)1£»¾Í¿ÉÒÔÁË¡£1ĬÈÏΪintÐÍ£¬1l²ÅÊÇlongÐÍ¡£
¶à¿´¿´ÊéÔÙÎÊ°É£¬ÔÙÓÐÎÊÌâ¿ÉÒÔ¼ÌÐøÎÊ
------½â¾ö·½°¸--------------------

4000000000ÊÇÕûÐÍ£¬Ö»ÓÐÔÚ4000000000ºó¼Ól»òL£¨4000000000l»ò4000000000L£©±àÒëÆ÷²Å»á°ÑËüµ±³¤ÕûÐÍ´¦Àí£¬
 long l=4000000000;
´ËÓï¾ä¿É½âÎöΪ°ÑÕûÐÍ4000000000¸³Öµ¸ø³¤ÕûÐÍl£¬¶ø4000000000³¬³öÁËintµÄÈ¡Öµ·¶Î§£¬ËùÒÔ±¨´í

------½â¾ö·½°¸--------------------
Short s = 1;
´ËÓï¾ä¿É½âÎöΪ°ÑÕûÐÍ1¸³Öµ¸ø¶ÌÕûÐÍs£¬¶ø1¼ÈÔÚintµÄÈ¡Öµ·¶Î§£¬Ò²ÔÚShortµÄÈ¡Öµ·¶Î§£¬ËùÒÔ²»±¨´í
------½â¾ö·½°¸--------------------
float ÄǸöÀý×Óµ¹ÊÇ¿ÉÒÔ½âÊÍ£¬ÒòΪ¼ÆËã»úµÄ¸¡µãÊý²¢²»¾«È·£¬ËùÒÔÄãд³ÉÁË1.1£¬ÏµÍ³²¢²»ÖªµÀÄãµÄÒâ˼ÊÇÒ»¸öfloat»¹ÊÇÒ»¸ödouble¡£±ÈÈçÈçÏ´úÂ룺
System.out.println(1.1 == 1.0999999999999999999);

½«»áÊä³ötrue

ÖÁÓÚShort s = 1; Õâ¸öÇé¿ö£¬ÎÒ¾õµÃ¿ÉÄÜÊÇÒ»ÖÖÓï·¨ÌÇ¡£ÒòΪÎÒÍøÉÏÕÒµ½µÄËùÓÐ×ÊÁÏÎÞÒ»ÀýÍⶼÊÇ˵ÐèÒª(short)µÄת»»¡£ÎÒÏë¿ÉÄÜÊDZàÒëÆ÷ÔÚ¿´µ½Õâ¸öÖµµÄÈ¡Öµ·¶Î§ÔÚshortÖ®ÄÚʱ£¬¾Í×Ô¶¯×ª»»³ÉshortÁË¡£µ«ÊÇĬÈϵÄÕûÐÍÀàÐÍ£¬ÈÔÈ»ÊÇint£¬ËùÒÔ²»ÄÜ×Ô¶¯×°Ïä³ÉLong
  Ïà¹Ø½â¾ö·½°¸