English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
في هذا البرنامج، ستتعلم كيفية تخزين إضافتهما وتصحيح مجموعهما في Java. بعد الإضافة، سيتم عرض المجموع النهائي على الشاشة.
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("Total: " + sum); } }
When running the program, the output is:
Enter two numbers: 10 20 Total: 30
In this program, two integers 10 and 20 are stored in integer variables first and second.
Then, use the + operator to add first and second, and store the result in another variable sum.
Finally, use the println() function to print the sum on the screen.