Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create add-two-integers.mdx
  • Loading branch information
arghyaxcodes committed May 17, 2022
commit 69ce44ecf5f37961fd07b65c957ff226dd996900
54 changes: 54 additions & 0 deletions src/pages/programs/add-two-integers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
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.