Receiving Input from the User




This video tutorial explains how to receive input from the user in java programming using System.in and Scanner class.

You are gonna learn how to create an object of Scanner class, how to associate System.in with it, how to read integer, floating point, character and boolean value from the user and store it in variable in detail with examples.


Source code for this video tutorial


package LearningJava;

import java.util.Scanner;

public class Anil {

 public static void main(String[] args) {


  Scanner input = new Scanner(System.in);
  
  int age;
  System.out.println("Enter your age");
  age = input.nextInt();
  
  System.out.println("Ok your age is " + age);
  
  System.out.println("Enter your avarage");
  double average = input.nextDouble();
  System.out.println("Ok your average is " + average);
  
  
  input.close();
  
  
 }

}