刚学Java 在模仿别人的代码 但是错误:找不到符号

System. out. println(" cubic centimetres.");
符号:方法 println(String)
位置:类型为PrintlnStream的变量 out

public class BoxVolume {

    public static void main(String[] args) {
    
            int width = 20;           // width of cube in cms
            double length = 30.5;     // length of cube in cms
            double depth = 10.5;      // depth of cube in cms
            
            // compute the volume
            double volume = width*length*depth;
            
            // write the result 
            System. out. print("Your box has a volume of ");
            System. out. print(volume);
            System. out. ptintln(" cubic centimetres.");
     }

}

D:\myJava> javac BoxVolume.java
BoxVolume.java:15: 错误: 找不到符号
System. out. ptintln(" cubic centimetres.");
^
符号: 方法 ptintln(String)
位置: 类型为PrintStream的变量 out
1 个错误

System. out. ptintln(" cubic centimetres.");
改成
System. out. println(" cubic centimetres.");

??不太合理
你贴一下报错和源代码截图看看

发图吧

img

img


就是粘贴你的代码运行的,没有报错,你看看你是不是把他的其他东西也打进来了,但你还没有定义,有用的话点一下采纳

System. out. println(" cubic centimetres.");
看起来没啥问题,编译器也能运行,不过写的时候建议规范点,去掉空格:
System.out.println(" cubic centimetres.");

可以运行,效果如下,是你把代码写错了,13行单词写错了

    public static void main(String[] args) {

        int width = 20;           // width of cube in cms
        double length = 30.5;     // length of cube in cms
        double depth = 10.5;      // depth of cube in cms

        // compute the volume
        double volume = width*length*depth;

        // write the result
        System.out.print("Your box has a volume of ");
        System.out.print(volume);
        System.out.println(" cubic centimetres.");
    }

img