Tuesday, 27 August 2013

Adding 2 Number using variable

class Program
{
public static void main(String []args)
{
int number1=2;
int number2=2;
int number3=number+number2;
System.out.println(number3);
}
}

OUTPUT
4

int number1=2;    : This line declare and give the value to integer variable.
int number2=2;    : This line declare and give the value to integer variable.
int number3=number+number2;  : This line also declare and give value to integer variable using previous variable.

System.out.println(number3);   : This give the output on console of variable (number3) that have contain value..

No comments:

Post a Comment