This java program will illustrate the addition of two integer numbers. This operation is an important aspect for programmer where this logic is going to apply for several applications. Keeping those things in mind we start the process of addition using java program.
The steps involved are :
The steps involved are :
we take two input from the user and using traditional " + " operator we add both the integer. As numbers are of the type "int" so we get the addition of both number as a result.
import java.util.Scanner; public class Add { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number1; // first number to add int number2; // second number to add int sum; // sum of number1 and number2 System.out.printf( "Enter first integer: " ); // prompt number1 = input.nextInt(); // read first number from user System.out.printf( "Enter second integer: " ); // prompt number2 = input.nextInt(); // read second number from user sum = number1 + number2; // add numbers System.out.printf( "Sum is %d\n", sum ); // display sum } }
No comments:
Write comments