Java Scanner Class

Post on January 5th,2012 by |Posted in programming languages | Tagged in , , | No Comment | Send Email

This quick tutorial will show you how to create a simple java program using Java scanner class. This program will ask for two integers, then sum them up and finally print out the answer on the screen. The simple code is as follow:


import java.util.Scanner;

public class PlusNumber {

  public static void main(String[] args) {

    int firstNumber;
    int secondNumber;
    int total;

    Scanner input = new Scanner(System.in);

    System.out.print("Enter first integer : ");

    firstNumber = input.nextInt();

    System.out.print("Enter second integer : ");

    secondNumber = input.nextInt();

    total = firstNumber + secondNumber;

    System.out.println("The total is : " + total);

   }

}

The outcome of the program is as follow:

Next Page :

Javascript replace method review

Javascript replace method review

How to use Java Scanner Class

This article will show you how to use Java Scanner Class with simple Java code.

Show text on JFrame with Java program

Show text on JFrame with Java program!

The if…else statement in Java program

‘The if…else statement in Java program’ article will show you an example to use the statement.

Creating and Using Interfaces in Java Program

Creating and Using Interfaces in Java Program will show you how to write simple java program using Interfaces.

Create a simple Java method

An article about how to create a simple Java method.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>