English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriais Básicos de Java

Controle de fluxo do Java

Array do Java

Java orientado a objetos (I)

Java orientado a objetos (II)

Java orientado a objetos (III)

Tratamento de Exceções Java

Lista (List) do Java

Fila (Queue) do Java

Conjunto Map do Java

Conjunto Set do Java

Entrada e saída do Java (I/O)

Reader do Java/Writer

Outros tópicos do Java

Adição de dois inteiros em programas Java

Java Examples Comprehensive

In this program, you will learn how to store and add two integers in Java. After addition, the final sum will be displayed on the screen.

Example: Program to add two integers

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

When running this program, the output is:

Enter two numbers: 10 20
Sum: 30

In this program, two integers10and20 to store in integer variables first and second.

Then, using + The operator adds first and second and stores the result in another variable sum.

Finally, use the println() function to print the sum on the screen.

Java Examples Comprehensive