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

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

المطلوب

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

Enter first number: 7
Enter second number: 2
Result: 7 > 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.print("Result: ");
if (x > y)
{
System.out.println(x + " > " + y);
}
else if (x < y)
{
System.out.println(x + " < " + y);
}
else
{
System.out.println(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.print("Result: "); if (x > y) { System.out.println(x + " > " + y); } else if (x < y) { System.out.println(x + " < " + y); } else { System.out.println(x + " = " + y); } } }

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

Enter first number: 7
Enter second number: 2
Result: 7 > 2