我被困在我的程序中。我需要帮助在 main 方法中使用函数。到目前为止,我有这个:
double x, y;
char op;
System.out.print("X: ");
x = keyboard.nextDouble();
System.out.print("Y: ");
y = keyboard.nextDouble();
System.out.print("Enter Operation: ");
op = keyboard.next().charAt(0);
do
{
if (op == '+');
System.out.print("..");
}
while (op != 'q');
System.out.print("Bye!");
}
public static double sum (double x, double y)
{
double sum = 0;
sum = (x + y);
return sum;
}
public static double minus (double x, double y)
{
double minus = 0;
minus = (x - y);
return minus;
}
public static double multiply (double x, double y)
{
double multiply = 0;
multiply = (x * y);
return multiply;
}
public static double divide (double x, double y)
{
double divide = 0;
divide = (x/y);
return divide;
}
对于“if 语句”,我想使用这些函数。如果运算是“+”,那么它将使用 sum 函数来添加 x 和 y。但是如何在“if 语句”中键入它?对不起。这是我的第二节编程课,所以我还在学习。