2. คำนวณ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 2-21  การเรียก nextLine เพื่ออ่านส่วนที่เหลือของบรรทัดทิ้งไป
    Scanner kb = new Scanner(System.in);
    System.out.print("กรุณาใส่จำนวนเต็ม > ");
    int n = kb.nextInt();
    kb.nextLine(); // อ่านที่เหลือของบรรทัดทิ้งไป 
    System.out.print("กรุณาใส่ข้อความ > ");
    String s = kb.nextLine();
    System.out.println(n + ", " + s);
©2009 S.Prasitjutrakul