ÔÚJavaÖÐʵÏÖ¸¡µãÊýµÄ¾«È·¼ÆËã
±êÌâ ÔÚJavaÖÐʵÏÖ¸¡µãÊýµÄ¾«È·¼ÆËã AYellow£¨Ô×÷£© ÐÞ¸Ä
¹Ø¼ü×Ö Java ¸¡µãÊý ¾«È·¼ÆËã
ÎÊÌâµÄÌá³ö£º
Èç¹ûÎÒÃDZàÒëÔËÐÐÏÂÃæÕâ¸ö³ÌÐò»á¿´µ½Ê²Ã´£¿
public class Test{
public static void main(String args[]){
System.out.println(0.05+0.01);
System.out.println(1.0-0.42);
System.out.println(4.015*100);
System.out.println(123.3/100);
}
};
ÄãûÓп´´í£¡½á¹ûȷʵÊÇ
0.060000000000000005
0.5800000000000001
401.49999999999994
1.2329999999999999
JavaÖеļòµ¥¸¡µãÊýÀàÐÍfloatºÍdouble²»Äܹ»½øÐÐÔËËã¡£²»¹âÊÇJava£¬ÔÚÆäËüºÜ¶à±à³ÌÓïÑÔÖÐÒ²ÓÐÕâÑùµÄÎÊÌâ¡£ÔÚ´ó¶àÊýÇé¿öÏ£¬¼ÆËãµÄ½á¹ûÊÇ׼ȷµÄ£¬µ«ÊǶàÊÔ¼¸´Î£¨¿ÉÒÔ×öÒ»¸öÑ»·£©¾Í¿ÉÒÔÊÔ³öÀàËÆÉÏÃæµÄ´íÎó¡£ÏÖÔÚÖÕÓÚÀí½âΪʲôҪÓÐBCDÂëÁË¡£
Õâ¸öÎÊÌâÏ൱ÑÏÖØ£¬Èç¹ûÄãÓÐ9.999999999999Ôª£¬ÄãµÄ¼ÆËã»úÊDz»»áÈÏΪÄã¿ÉÒÔ¹ºÂò10ÔªµÄÉÌÆ·µÄ¡£
ÔÚÓеıà³ÌÓïÑÔÖÐÌṩÁËרÃŵĻõ±ÒÀàÐÍÀ´´¦ÀíÕâÖÖÇé¿ö£¬µ«ÊÇJavaûÓС£ÏÖÔÚÈÃÎÒÃÇ¿´¿´ÈçºÎ½â¾öÕâ¸öÎÊÌâ¡£
ËÄÉáÎåÈë
ÎÒÃǵĵÚÒ»¸ö·´Ó¦ÊÇ×öËÄÉáÎåÈë¡£MathÀàÖеÄround·½·¨²»ÄÜÉèÖñ£Áô¼¸Î»Ð¡Êý£¬ÎÒÃÇÖ»ÄÜÏóÕâÑù£¨±£ÁôÁ½Î»£©£º
public double round(double value){
return Math.round(value*100)/100.0;
}
·Ç³£²»ÐÒ£¬ÉÏÃæµÄ´úÂë²¢²»ÄÜÕý³£¹¤×÷£¬¸øÕâ¸ö·½·¨´«Èë4.015Ëü½«·µ»Ø4.01¶ø²»ÊÇ4.02£¬ÈçÎÒÃÇÔÚÉÏÃæ¿´µ½µÄ
4.015*100=401.49999999999994
Òò´ËÈç¹ûÎÒÃÇÒª×öµ½¾«È·µÄËÄÉáÎåÈ룬²»ÄÜÀûÓüòµ¥ÀàÐÍ×öÈκÎÔËËã
java.text.DecimalFormatÒ²²»Äܽâ¾öÕâ¸öÎÊÌ⣺
System.out.println(new java.text.DecimalFormat("0.00").format(4.025));
Êä³öÊÇ4.02
BigDecimal
ÔÚ¡¶Effective Java¡·Õâ±¾ÊéÖÐÒ²Ìáµ½Õâ¸öÔÔò£¬floatºÍdoubleÖ»ÄÜÓÃÀ´×ö¿Æѧ¼ÆËã»òÕßÊǹ¤³Ì¼ÆË㣬ÔÚÉÌÒµ¼ÆËãÖÐÎÒÃÇÒªÓÃjava.math.BigDecimal¡£BigDecimalÒ»¹²ÓÐ4¸ö¹»Ôì·½·¨£¬ÎÒÃDz»¹ØÐÄÓÃBigIntegerÀ´¹»ÔìµÄÄÇÁ½¸ö£¬ÄÇô»¹ÓÐÁ½¸ö£¬ËüÃÇÊÇ£º
BigDecimal(double val)
 
Ïà¹ØÎĵµ£º
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
ΪÁËʹ²Ù×÷ϵͳ֧³ÖJava£¬¿ÉÓÉSun¹«Ë¾µÄJavaÏÂÔØÍøÒ³, ¸ù¾Ý²Ù×÷ϵͳÀàÐÍÏÂÔغͰ²×°Ò»¸öÃâ·ÑJRE(Java Runtime Environment), ÀýÈç, JRE6¡£È»ºó, ½«±¾ÎļþÏÂÔر£´æ, ¿½±´, ²¢Õ³Ìùµ½JREËùÔÚµÄsecurityĿ¼, ÀýÈç, C:/Program Files/Java/jre6/lib/security/, Ìæ»»ÔÓеÄÎļþjava.policy, ÉèÖÃJREÍê³É¡£
......
//1.´´½¨testdll.javaÎļþ
public class testdll
{
static
{
System.loadLibrary("goodluck");
}
public native static int get();
public native static void set(int i);
public static void main(String[] args)
{
testdll test = new testdll();
test.set(10);
System.out.println(test.get() ......
Java ÖÐÀàºÍ·½·¨ÐÞÊηû
ÀàµÄÐÞÊÎ
·ÃÎÊÐÞÊηû ÐÞÊηû class ÀàÃû extends ¸¸ÀàÃû³Æ implements ½Ó¿ÚÃû³Æ£¨notes: ·ÃÎÊÐÞÊηû·ûÓëÐÞÊηûµÄλÖÿÉÒÔ»¥»»£©
·ÃÎÊÐÞÊηû
Ãû³Æ
˵Ã÷
±¸×¢
pubic
¿ÉÒÔ±»ËùÓÐÀà·ÃÎÊ(ʹÓÃ)
public Àà±ØÐ붨ÒåÔÚºÍÀàÃûÏàͬµÄͬÃûÎļþÖÐ
package
¿ÉÒÔ±»Í¬Ò»¸ö°üÖеÄÀà·ÃÎÊ(ʹÓÃ)
ĬÈϵķÃÎ ......
±êÌâ ÔÚJavaÖÐʵÏÖ¸¡µãÊýµÄ¾«È·¼ÆËã AYellow£¨Ô×÷£© ÐÞ¸Ä
¹Ø¼ü×Ö Java ¸¡µãÊý ¾«È·¼ÆËã
ÎÊÌâµÄÌá³ö£º
Èç¹ûÎÒÃDZàÒëÔËÐÐÏÂÃæÕâ¸ö³ÌÐò»á¿´µ½Ê²Ã´£¿
public class Test{
public static void mai ......