Simple calculator using Scanner object

 Below java class will explain you how to use the Scanner object which is a part of java.util package. This class is basically for integer values only however you can use the same way for double, float etc.


import java.util.Scanner;

public class Calculator {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter your first integer value: ");
        int first = in.nextInt();
        System.out.println("Enter your second integer value: ");
        int second = in.nextInt();

        int plus = first + second;
        int minus = first - second;
        int multiply = first * second;
        int divide = first / second;

        System.out.println("Summation for " + first + " and " + second
                + " is: \t\t" + plus);
        System.out.println("Subtraction for " + first + " and " + second
                + " is: \t\t" + minus);
        System.out.println("Multiplication for " + first + " and " + second
                + " is: \t" + multiply);
        System.out.println("Division for " + first + " and " + second
                + " is: \t\t" + divide);
    }
}


Output:

Enter your first integer value: 
50
Enter your second integer value: 
50
Summation for 50 and 50 is:       100
Subtraction for 50 and 50 is:     0
Multiplication for 50 and 50 is:  2500
Division for 50 and 50 is:        1

5 comments:

  1. what is thee use of /t/t...?????

    ReplyDelete
    Replies
    1. i daont know



      Delete
    2. it adds a tab
      a couple of spaces

      Delete
  2. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete
  3. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog. It is very nicely explained. Your article adds best knowledge to our Java Online Training from India. or learn thru Java Online Training from India Students.

    or learn thru JavaScript Online Training from India. Appreciating the persistence you put into your blog and detailed information you provide. Kindly keep blogging.

    ReplyDelete