javaÒì³£´¦Àí
Ö»Õë¶Ô²»Õý³£µÄÌõ¼þ²ÅʹÓÃÒì³£
Òì³£Ö»Ó¦¸Ã±»ÓÃÓÚ²»Õý³£µÄÌõ¼þ£¬ËüÃÇÓÀÔ¶²»Ó¦±»ÓÃÓÚÕý³£µÄ¿ØÖÆÁ÷¡£
ÏÂÃæÊÇÒ»¸öÓÃÒì³£×÷±éÀú½áÊøÌõ¼þµÄÀÄÓÃÒì³£µÄÀý×Ó£º
//horrible abuse of exceptions. Don't ever do this!
try{
int i=0;
while(true)a[i++].f();
}catch(ArrayIndexOutOfBoundsException e){
...
}
Æä´íÓÐÈý£º
1¡¢´´½¨¡¢Å׳öºÍ²¶»ñÒì³£µÄ¿ªÏúÊǺܰº¹óµÄ¡£ÒòΪËüµÄ³õÖÔÊÇÓÃÓÚ²»Õý³£µÄÇéÐΣ¬ÉÙÓÐjvm»áËü½øÐÐÐÔÄÜÓÅ»¯¡£
2¡¢°Ñ´úÂë·ÅÔÚtry-catchÖлá×èÖ¹jvmʵÏÖ±¾À´¿ÉÄÜÒªÖ´ÐеÄijЩÌض¨µÄÓÅ»¯¡£
3¡¢ÓÐЩÏÖ´úµÄjvm¶ÔÑ»·½øÐÐÓÅ»¯£¬²»»á³öÏÖÈßÓàµÄ¼ì²é¡£
ÍêÈ«¿ÉÒÔʹÓñê×¼µÄʵÏÖ·½Ê½£º
for(int i=0;i<a.length;i++){
a[i].f();
}
ÕâÌõÔÔòÒ²ÊÊÓÃÓÚAPIÉè¼Æ¡£Ò»¸öÉè¼ÆÁ¼ºÃµÄAPI²»Ó¦¸ÃÇ¿ÆÈËüµÄ¿Í»§ÎªÁËÕý³£µÄ¿ØÖÆÁ÷¶øʹÓÃÒì³£¡£Èç¹ûÀàÖÐÓÐÒ»¸ö”״̬Ïà¹Ø”µÄ·½·¨£¬¼´Ö»ÓÐÌض¨µÄÌõ¼þÏ¿ɱ»µ÷Óõķ½·¨£¬ÔòÕâ¸öÀàÒ²Ó¦ÓÐÒ»¸öµ¥¶ÀµÄ“״̬²âÊÔ”·½·¨£¬ÒÔΪµ÷ÓÃÕâ¸ö״̬Ïà¹Ø·½·¨Ç°µÄ¼ì²é¡£ÈçCollectionÀàµÄnext·½·¨ºÍ hasNext·½·¨¡£
for(Iterator i=collection.iterator();i.hasNext();){
Foo foo=(Foo)i.next();
...
}
¶ÔÓڿɻָ´µÄÌõ¼þʹÓñ»¼ì²éµÄÒì³££¬¶ÔÓÚ³ÌÐò´íÎóʹÓÃÔËÐÐʱÒì³£
javaÌṩÁËÈýÖÖ¿ÉÅ׳öµÄÒì³££º±»¼ì²éµÄÒì³££¨checkedException£©¡¢ÔËÐÐʱÒì³££¨run-time Exception£©ºÍ´íÎó(error)¡£¡¡¡¡Èç¹ûÆÚÍûµ÷ÓÃÕßÔÚµ÷ÓÃʱ³öÏÖµÄÒì³£Äܹ»»Ö¸´£¬ÔòÓ¦¸ÃʹÓñ»¼ì²éµÄÒì³££¬Í¨¹ýÅ׳öÒ»¸ö±»¼ì²éµÄÒì³££¬Ç¿Æȵ÷ÓÃÕßÔÚcatchÖд¦Àí¸ÃÒì³££¬»òÕß½«Òì³£´«²¥µ½ÍâÃæ¡£
¡¡¡¡¶ÔÓÚÒ»¸ö·½·¨ÉùÃ÷ÒªÅ׳öµÄÿһ¸ö±»¼ì²éµÄÒì³££¬ËüÊǶÔAPIÓû§µÄÒ»ÖÖDZÔÚָʾ£ºÓëÒì³£Ïà¹ØÁªµÄÌõ¼þÊǵ÷ÓÃÕâ´Î¸ö·½·¨µÄÒ»ÖÖ¿ÉÄܽá¹û¡£
¡¡¡¡Á½ÖÖδ±»¼ì²éµÄ¿ÉÅ׳ö½á¹¹£ºÔËÐÐʱÒì³£ºÍ´íÎó£¬ÔÚÐÐΪÉÏÏàͬµÄ£¬ËüÃǶ¼²»ÐèÒª¡¢Ò²²»Ó¦¸Ã±»²¶»ñµÄÅ׳öÎï¡£ÄãËùʵÏÖµÄËùÓÐδ±»¼ì²éµÄÅ׳ö½á¹¹¶¼Ó¦ÊÇ RuntimeExceptionµÄ×ÓÀà¡£¶¨ÒåÒ»¸ö·ÇException¡¢RuntimeException»òError×ÓÀàµÄÅ׳öÎïÊÇ¿ÉÐеģ¬µ«´ÓÐÐΪÒâÒåÉÏËüµÈͬÓÚ±»ÆÕͨµÄ±»¼ì²éÒì³££¨¼´Exception×ÓÀà¶ø·ÇRuntimeException×ÓÀࣩ.
±ÜÃâ²»±ØÒªµØʹÓñ»¼ì²éµÄÒì³£
Óë·µ»Ø´úÂ벻ͬ£¬±»¼ì²éµÄÒ쳣ǿÆȳÌÐò´¦ÀíÀýÍâµÄÇé¿ö£¬´Ó¶ø´ó´óµØÌá¸ßÁ˳ÌÐòµÄ¿É¿¿ÐÔ¡£¶ø¹ý·ÖµØʹÓñ»¼ì²éµÄÒì³£
Ïà¹ØÎĵµ£º
£¨
1
£©
+=
:sum += 1;
Ï൱ÓÚ
sum = sum + 1;
£¨
2
£©
++ --
:i++ i
¼Ó
1, i-- i
¼õ
1, ++
»ò
—
·ÅÔÚÊýÖµºó£¬±íʾִÐÐÔËËãºó¼Ó£¨¼õ£©
1
£¬·´ÕýÊýֵǰ±íʾִÐÐÔËËãÇ°¼Ó£¨¼õ£©
1
£¨
3
£©
?
: :
int n = a<10?1:2
±íʾÈç¹û
a
СÓÚ
10
Ôò
n
µÈÓÚ
1
·ñÔòµÈÓÚ
2
£¨
4
......
Java±àдһ¸öº¯Êý½»»»Á½¸ö±äÁ¿µÄÖµ
Javaº¯ÊýÔÚ´«µÝ¹ý³ÌÖÐÖ»Äܹ»´«Öµ£¬²»ÄÜ´«Ö·¡£ÕâÑù£¬º¯ÊýµÄ²ÎÊýÔÚº¯ÊýÄÚ²¿×öÈκα仯¾Í¶¼²»»á·´Ó³µ½Íⲿµ÷ÓÃÕßÀ´¡£ËùÒÔ½â¾öÖ®µÀ¾ÍÊÇÒªÕÒµ½Òª½»»»¶ÔÏóµÄÒýÓ᣶ÔÓÚÆÕͨµÄÖµÀàÐÍ£¬Ïñint»òÕßdoubleÕâÑùµÄ¿ÉÒԸĴ«ËûÃǵİü×°ÀàIntegerºÍDouble¡£¶ø¶ÔÓÚ±¾À´¾ÍÊÇÒýÓÃÀàÐ͵ĶÔÏó£¬ÔòÐèÒª¶ÔËûÃÇÔÙ ......
ÕâÊÇÒ»¸ö·Ç³£¼òµ¥µÄJavaÆåÀàÓÎÏ·£¨ßÀ£¬²»Ð¡ÐÄÑ¡ÁËÒ»ÕÅÕ¼Óÿռä±È½Ï´óµÄ±³¾°Í¼……£©£¬ÎÒÖ´ºì·½£¬µÐÖ´À¶·½£¬Ê×ÏȽ«ÉÏÏ»ò×óÓÒÁ½¶ËÆå×Ó¹áͨÕß¼´ÎªÊ¤Àû£¬ÒÔLGame-Simple-0.2.5¿ª·¢£¨Ô´ÂëÔÚjarÖУ©¡£
ÊÂʵÉÏ£¬ÎÒÃǾ³£¿ÉÒÔÔÚÍøÂçÖп´µ½ÓÐЩÍøÓÑ·´¸´Ñ°ÕÒÖîÈçÎå×ÓÆ塢ΧÆå¡¢ÏóÆåÖ®ÀàСÓÎÏ·µÄʾÀý³ÌÐò¡£Ã÷Ã÷ÍøÂçÉÏͬÀ ......
¸ÅÊö
Èç¹ûÄãÖªµÀÔõÑùÔÚjavaÖÐʹÓÃÈÕÆÚ£¬ÄÇôʹÓÃʱ¼äºÍËü²Å²»¶àÒ»Ñù¼òµ¥¡£ÕâƪÎÄÕ¸æËßÄãÔõÑù°ÑËûÃǵIJî±ðÁªÏµÆðÀ´¡£Robert Nielsen»¹¸æËßÄãÔõÑùʹÓÃjavaÀ´¼ÆËãµÖ´ïº½°àºÍÖÆÔì¹ý³ÌµÄʱ¼ä¡£
×÷ÕߣºRobert Nielsen
·Ò룺Cocia Lin
ÕâƪÎÄÕÂÊÇÔÚÎÒ·¢±í¹ýµÄ<¼ÆËãJavaʱ¼ä>(ÒëÕß:ÒѾ·ÒëÍê³É)µÄ»ù´¡Éϵġ£ÔÚÕâÀΠ......
package homework03;
import java.util.Scanner;
/*
* ±àдһ¸öÀ࣬¸ÃÀàÓÐÒ»¸ö·½·¨
* public int f£¨int a£¬int b£©{
*
* }
* È»ºó±àдһ¸ö¸ÃÀàµÄ×ÓÀ࣬ҪÇóÖØд·½·¨f()£¬¶øÇÒÖØдµÄ·½·¨½«·µ»ØÁ½¸öÕûÊýµÄ×îС¹«±¶Êý¡£ÒªÇó£º
* ÔÚÖØдµÄ·½·¨µÄ·½·¨ÌåÖÐÊ×Ïȵ÷Óñ»Òþ²ØµÄ·½·¨·µ»ØaºÍbµÄ×î´ó¹«Ô¼Êým,È»ºó½«a*b/m ......