Friday, 19 August 2016

Java Tutorial : Java IO (Scanner class - Read numbers from Keyboard)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=rCsBg9VujdM&list=UUhwKlOVR041tngjerWxVccw

ScannerDemo.java
import java.util.Scanner;

public class ScannerDemo
{

    public static void main(String[] args)
    {
        Scanner scanner = null;
        try
        {
            scanner = new Scanner(System.in);
            System.out.print("Enter the first number: ");
            int number1 = scanner.nextInt();
            System.out.print("Enter the second number: ");
            int number2 = scanner.nextInt();

            int sum = number1 + number2;
            System.out.println("sum = " + sum);

        }
        finally
        {
            if (scanner != null)
            {
                scanner.close();
            }
        }

    }
}
Output
Enter the first number: 10
Enter the second number: 20
sum = 30

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_Scanner_sum_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_Scanner_sum_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/16638d65b46bec1088dab744ba69a31424c4a14f/BasicJava/JavaIODemo_Scanner_sum_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge