如何使此代码有效? .class预期错误 [英] How do I make this code work? .class expected error

查看:66
本文介绍了如何使此代码有效? .class预期错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class  LemonadeStand
{
  public static void main(String [] args)
  {
    printTotalSales(int numSales, double price);
  }
  public static double printTotalSales(int numSales, double price);
  {
    double revenue = printTotalSales(17 * 4.45);
    return revenue;
    System.out.println("We sold " + "units at " + "each, which totals ");
  }
}





我的尝试:



我已经重读了我的笔记,重写了教授的讲座,但仍然无法弄清楚我正在打字的内容有什么问题。我已经过去三个小时了。错误发生在printTotalSales(int numSales,double price);但我不知道它是什么。



What I have tried:

I have reread my notes, rewatched the prof's lecture, and still cannot figure out what's wrong with what I'm typing. I've been at it for the past three hours already. The error is at printTotalSales(int numSales, double price); but I don't know what it is.

推荐答案

代码存在一些问题。



1.主要方法应该使用sales和price参数调用printTotalSales,见下文。

2.在方法声明之后,语法错误

3. println将不会被执行

4.不清楚为什么代码需要递归调用printTotalSales方法。它应该只是销售*价格并返回收入



There are some issue with the code.

1. The main method should call the printTotalSales with the sales and price parameter, see below.
2. The ; after the method declaration , syntax error
3. The println will not get executed
4. Not clear why the code need to call the method printTotalSales recursively. It should be simply sales * price and return the revenue

public class LemonadeStand {
    public static void main(String args[]) {
        System.out.println("Total Sales = " +     printTotalSales(17,4.45));
    }
    
   public static double printTotalSales(int numSales, double price)
    {
        double revenue = numSales * price;
        
        System.out.println("We sold " + numSales +  " units at "+ price + "each, which totals ");
        return revenue;
    }
}


这篇关于如何使此代码有效? .class预期错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆