How to use Scanner class in java?

1 Like

This class is introduce java 1.5 version and it can be used to Read the contents from a resource.


import java.util.*;

class Read{

public static void main(String[] args) throws IOException{

Scanner s = new Scanner(;

System.out.println(“Enter your age:”);

String str = s.nextLine();

Int age = Integer.parseInt(str);

System.out.println(“Age:” + age);