Showing posts with label java computation. Show all posts
Showing posts with label java computation. Show all posts

Sunday, April 18, 2010

Compute two numbers in java using user input

this program will ask the user to input two numbers and get the sum.

import java.io.*;
import java.util.Scanner;

public class getsum
{
public static void main(String args[])
{

Scanner input=new Scanner(System.in);
int num1,num2;
int sum=0;

System.out.print("Enter First Number:");
num1=input.nextInt();

System.out.print("Enter Second Number:");
num2=input.nextInt();

sum=num1+num2;

System.out.print("The sum is:" + sum);


}
}