Java - Adding Two Numbers
Here is the Java Source Code for adding two numbers.
Source Code
import java.io.*;
class AddNumbers {
public static void main(String[] args) {
String inpstring = "";
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
try
{
System.out.println("Program for Adding Two Numbers");
System.out.print("Enter First Number:");
inpstring = reader.readLine();
int a = Integer.parseInt(inpstring);
System.out.print("Enter Second Number:");
inpstring = reader.readLine();
int b = Integer.parseInt(inpstring);
System.out.println("Result: " + (a + b));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Output
C:\Java\Samples>javac AddNumbers.java
C:\Java\Samples>java AddNumbers
Program for Adding Two Numbers
Enter First Number:10
Enter Second Number:20
Result: 30
|