---
title: Java Program to Add Two Integers
shortTitle: Add Two Integers
description: In this program, you'll learn to store and add two integer numbers in Java. After addition, the final sum is displayed on the screen.
---

import { List, ListItemGood } from '@/components/List'


The integer is stored in a variable using `System.in`, and is displayed on the screen using `System.out`.

To understand this example, you should have the knowledge of the following Java programming topics:

- [Java Operators](/docs/operators)
- [Java Basic Input and Output](/docs/basic-input-output)

## 1. Add Two Integers

A Java program that add two numbers predefined by the user is as follows:

### Example: Program to Add Two Integers

#### Input

```java
class Main {

  public static void main(String[] args) {
    
    System.out.println("Enter two numbers");
    int first = 10;
    int second = 20;
    
    System.out.println(first + " " + second);

    // add two numbers
    int sum = first + second;
    System.out.println("The sum is: " + sum);
  }
}
```

#### Output

```text
Enter two numbers
10 20
The sum is: 30
```
In this program, two integers `10` and `20` are stored in integer variables `first` and `second` respectively.

Then, `first` and `second` are added using the `+` operator, and its result is stored in another variable `sum`.

Finally, `sum` is printed on the screen using `println()` function.