Scanner Object to read console input

by rajesh 2009-12-30 16:41:04

java.util.Scanner can be used to read a from the console..

Example Code

import java.util.Scanner;

public class Scanning {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       // read a single line from the console 
       String name = in.nextLine();

       // read next int from the console
       int age = in.nextInt();

       in.close();            
    }
}

Tagged in:

1400
like
0
dislike
0
mail
flag

You must LOGIN to add comments