In this Example we Reading the numbers and string in the class Scanner becomes analogous to reading string. In this example, the two numbers are read from the console, results printed on the screen formatted output.
import java.util.*; class InputDemo { public static void main (String args [ ]) { int a,b; double pi; String name; Scanner s=new Scanner(System.in); System.out.println("Enter thevalue of a & b "); a=s.nextInt( ); b=s.nextInt( ); System.out.println("Enter the value of pi "); pi=s.nextDouble( ); System.out.println("Enter the your name "); name=s.next( ); System.out.println("The value of a = "+a); System.out.println("The value of b = "+b); System.out.println("The value of pi = "+pi); System.out.println("Name = "+name ); } }