gpt4 book ai didi

java - 无法在命令行中编译程序但可以在 Eclipse 上运行?

转载 作者:行者123 更新时间:2023-12-01 07:57:16 27 4
gpt4 key购买 nike

我有两个类:我无法在命令行中编译它们中的任何一个:我正在使用 javac SodaCan.java 提示符,但它仍然无法编译,它显示如下内容:“错误:类、接口(interface)或枚举double、sodaCan、getvolume 等的预期“。

public SodaCan{
private double sArea;
private double volume;

public SodaCan(double height, double radius){
getSurfaceArea(height);
getVolume(radius);
}

public double getSurfaceArea(double height, double radius){
sArea = 2*Math.PI * Math.pow(radius, 2) + 2 * Math.PI * radius * height;

return sArea;
}

public double getVolume(double height, double radius){
volume = Math.PI * Math.pow(radius, 2) * height;
}
}

import java.util.*;

public class testSodaCan{
public static void main(String[] args){
double height, radius;
Scanner s = new Scanner(System.in);
System.out.println("Please input the height of the can: ");
height = s.nextDouble();
System.out.println("Please input the width of the can: ");
radius = s.nextDouble();
SodaCan can = new SodaCan(height, radius);
}
}

最佳答案

添加类关键字

public class SodaCan {

关于java - 无法在命令行中编译程序但可以在 Eclipse 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28431887/

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