This is very simple, just define two integer variables and use + operator to add them.
package JavaQuestions;
/**
*
* @author NaveenKhunteta
*
*/
public class AddNumbers {
public static void main(String[] args) {
int a = 10;
int b = 20;
int sum = a + b;
System.out.println("sum of a and b is: " + sum);
}
}
Output:
sum of a and b is: 30
Leave a Reply