gpt4 book ai didi

java - 错误: '.class' expected amongst 7 other errors

转载 作者:行者123 更新时间:2023-12-02 08:58:08 25 4
gpt4 key购买 nike

抱歉,我是一个 Java 编程初学者。有人能明白为什么我的程序给我这些错误消息吗?

错误消息如下:

MonthlyPhoneCostVer2.java:13: error: '.class' expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
^
MonthlyPhoneCostVer2.java:13: error: ';' expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
^
MonthlyPhoneCostVer2.java:13: error: ';' expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
^
8 errors

这是我的代码:

import javax.swing.*;
public class MonthlyPhoneCostVer2{
public static void main (String [] args){
double a = 2.50; // cost/min for day call
double b = 0.55; // cost/min for evening and weekend calls
double c = 50; // static monthly subscription cost
double d = 0.60; // cost for opening a phone call . cant have ',' in value
double x = Integer.parseInt(JOptionPane.showInputDialog(null, "Number of Phone Calls?"));
double y = Integer.parseInt(JOptionPane.showInputDialog(null, "Minutes of day calls"));
double z = Integer.parseInt(JOptionPane.showInputDialog(null, "Minutes of evening weekend calls"));
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
JOptionPane.showMessageDialog(null, "Your Total Cost of Phone Fees is: " + res);
}
public static double isCost(double a, double b, double c, double d, double x, double y, double z){
return ((x*d) + (y*a) + (z*b) + c);
}
}

最佳答案

您对 isCost 的方法调用具有不正确语法。这个

double res = isCost(double a, double b, double c, double d, double x, double y, double z);

应该是

double res = isCost(a, b, c, d, x, y, z);

我不清楚为什么您觉得需要(再次)添加调用者的类型信息,但这根本不正确。

关于java - 错误: '.class' expected amongst 7 other errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60366579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com