Search the Whole World Here.,.,

Java program to add two numbers



Step 1. Open the Notepad.













Step 2. Now just Copy and Paste the code in Notepad.


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);
   }
}


Step 3. Save the file as name.java







Step 4. Now open Command Prompt.
Step 5. Type cd desktop and Press Enter.
Step 6. Now type javac name.java and Press Enter.














Step 7. At last type java AddNumbers and then Press Enter.

Step 8. Enter 2 Numbers of your choice.
Output:


EmoticonEmoticon