أكتب برنامج java يطلب من المستخدم إدخال رقمين, ثم يعرض له قائمة خيارات يمكن تطبيقها على هذين الرقمين
- برمجة جافا
- 2022-02-17
- jannatmohammed
الأجوبة
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double a, b;
int option = -1;
System.out.print("Enter first number: ");
a = input.nextDouble();
System.out.print("Enter second number: ");
b = input.nextDouble();
System.out.println(
"\nWrite down the operation number then press enter\n"
+ "0: To end the program.\n"
+ "1: To print the sum.\n"
+ "2: To print the subtraction.\n"
+ "3: To print the multiplication.\n"
+ "4: To print the division.");
while (option != 0)
{
System.out.println("-------------------------");
System.out.print("Enter option: ");
option = input.nextInt();
switch (option)
{
case 0:
System.out.println("Program end.");
break;
case 1:
System.out.println(a + " + " + b + " = " + (a + b));
break;
case 2:
System.out.println(a + " - " + b + " = " + (a - b));
break;
case 3:
System.out.println(a + " * " + b + " = " + (a * b));
break;
case 4:
System.out.println(a + " / " + b + " = " + (a / b));
break;
}
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال