Programming Basics SQL HTML CSS JavaScript Python C++ Java JavaFX Swing Problem Solving English English Conversations Computer Fundamentals Learn Typing

تحديات برمجيةالتحدي الأول - حل التمرين الخامس بلغة جافا

المطلوب

أكتب برنامج يطلب من المستخدم إدخال رقمين, ثم يعرض له ناتج جمعمها, طرحهما, ضربهما و قسمتهما.
مثال: إذا قام المستخدم بإدخال الرقمين 14 و 5 فستكون النتيجة كالتالي.

Enter first number: 14
Enter second number: 5
14 + 5 = 19
14 - 5 = 9
14 * 5 = 70
14 / 5 = 2
	

الحل بلغة جافا

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x, y;
System.out.print("Enter first number: ");
x = input.nextInt();
System.out.print("Enter second number: ");
y = input.nextInt();
System.out.println(x + " + " + y + " = " + (x + y));
System.out.println(x + " - " + y + " = " + (x - y));
System.out.println(x + " * " + y + " = " + (x * y));
System.out.println(x + " / " + y + " = " + (x / y));
}
}
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x, y; System.out.print("Enter first number: "); x = input.nextInt(); System.out.print("Enter second number: "); y = input.nextInt(); System.out.println(x + " + " + y + " = " + (x + y)); System.out.println(x + " - " + y + " = " + (x - y)); System.out.println(x + " * " + y + " = " + (x * y)); System.out.println(x + " / " + y + " = " + (x / y)); } }

سنحصل على النتيجة التالية إذا قام المستخدم بإدخال الرقمين 14 و 5 عند التشغيل.

Enter first number: 14
Enter second number: 5
14 + 5 = 19
14 - 5 = 9
14 * 5 = 70
14 / 5 = 2