Follow on Facebook

Like and Share on Facebook

Saturday, February 7, 2015

Write a Program to add Two Number in Java


Write a Program to add Two Number in Java


import java.io.*;
class AddNumbers
{
   public static void main(String args[])
   {
      int x, y, z;
        x=10; y=12;
       z = x + y;
      System.out.println("Sum of entered integers = "+z);
   }
}

Output:
Sum of entered integers=22

Write a Program to add Two Number in Java Using Scanner


import java.util.Scanner;
class AddNumbers
{
   public static void main(String args[])
   {
      int x, y, z;
      System.out.println("Enter two integers to calculate their sum ");
      Scanner in = new Scanner(System.in);
      x = in.nextInt();
      y = in.nextInt();
      z = x + y;
      System.out.println("Sum of entered integers = "+z);
   }
}

Output:
Enter two integers to calculate their sum
89
11
Sum of entered integers=100

No comments:

Post a Comment