The Java program given below will add two integer numbers and will store the result into a variable. Later the result will be displayed with the appropriate message. Actually I have used three integer type variables a, b, sum. The variables a, b, sum are initialized with the values 5, 7 and 0 sequentially.
Later, I have added a and b, stored the result into the variable sum using the line sum=a+b;
Finally, I have showed the result using the line System.out.println("The addition is="+sum); We have to use the line System.out.println("any message"); to print any message. sum in the line System.out.println("The addition is="+sum); is used to print the data stored into it. And + (plus sign) is used to concatenate the stored result with the message.
Java program to add two integer numbers...public class Addition
{
public static void main(String [] args)
{
int a=5;
int b=7;
int sum=0;
sum=a+b;
System.out.println("The addition is="+sum);
} }
No comments:
Post a Comment