ããå¯ä»¥ç¨Scannerç±»çnextæ¹æ³å®ç°ï¼
public static void main(String[] args) {ããå®æ¯ä»¥åçStringTokenizeråMatcherç±»ä¹é´çæç§ç»åãç±äºä»»ä½æ°æ®é½å¿
é¡»éè¿åä¸æ¨¡å¼çæè·ç»æ£ç´¢æéè¿ä½¿ç¨ä¸ä¸ªç´¢å¼æ¥æ£ç´¢ææ¬çå个é¨åãäºæ¯å¯ä»¥ç»å使ç¨æ£å表达å¼åä»è¾å
¥æµä¸æ£ç´¢ç¹å®ç±»åæ°æ®é¡¹çæ¹æ³ã
ããè¿æ ·ï¼é¤äºè½ä½¿ç¨æ£å表达å¼ä¹å¤ï¼Scannerç±»è¿å¯ä»¥ä»»æå°å¯¹å符串ååºæ¬ç±»å(å¦intådouble)çæ°æ®è¿è¡åæã
ããåå©äºScannerï¼å¯ä»¥é对任ä½è¦å¤ççææ¬å
容ç¼åèªå®ä¹çè¯æ³åæå¨ã
ããScanneræ¯SDK1.5æ°å¢çä¸ä¸ªç±»,å¯æ¯ä½¿ç¨è¯¥ç±»å建ä¸ä¸ªå¯¹è±¡.ãã
Scanner reader=new Scanner(System.in);ãã
ç¶åreader对象è°ç¨ä¸åæ¹æ³(å½æ°),读åç¨æ·å¨å½ä»¤è¡è¾å
¥çåç§æ°æ®ç±»å:ãã
next.Byte(),nextDouble(),nextFloat,nextInt(),nextLine(),nextLong(),nextShot()ãã
ä¸è¿°æ¹æ³æ§è¡æ¶é½ä¼é æå µå¡,çå¾
ç¨æ·å¨å½ä»¤è¡è¾å
¥æ°æ®å车确认.ä¾å¦,æ¥æ¤å¨é®çè¾å
¥12.34,hasNextFloat()çå¼æ¯true,èhasNextInt()çå¼æ¯false. NextLine()çå¾
ç¨æ·è¾å
¥ä¸ä¸ªææ¬è¡å¹¶ä¸å车,该æ¹æ³å¾å°ä¸ä¸ªStringç±»åçæ°æ®ã