Programming Fundamentals

Java Scanner

Use of Java Scanner API:

import java.util.Scanner;

public class JavaScanner
{
public static void main(String[ ] args)
{
// create a object of java scanner class
Scanner sc = new Scanner(System.in);
// get the integer input from a user and store it in variable num
int num = sc.nextInt( );
// display the entered number by the user
System.out.print(“You typed: ” + num);
} // end-main

} // end-class JavaScanner

%d bloggers like this: