“错误:'。class''

时间:2013-10-15 15:06:32

标签: java

所以我是Java新手,我最近的一段代码没有用。我得到error: not a statement两次,error: ';' expected一次。

如果我尝试radius=double;,则会在第8行显示错误:Error: '.class' expected,其中插入符号显示在分号下。

我不确定有什么问题,但这是我的代码。不久......谢谢你。

import java.util.Scanner;
import static java.lang.Math;

public class Formula {
    public static void main(String[] args);{
    double = radius;

        Scanner in = new Scanner(System.in);
        System.out.print("Radius of circle (cm) :> ");
        double radius = in.nextDouble();
        System.out.print("Area of circle :> " + Math.PI * Math.pow(radius,2));
        System.out.print("Circumference of circle :> " + 2 * Math.PI * radius);
        System.out.print("Surface area the sphere with that radius :> " + 4 * Math.PI * Math.pow(radius,2));
        System.out.print("Volume of sphere with that radius :> " + 4/3 * (radius * Math.pow(radius,2)));

    }
}

6 个答案:

答案 0 :(得分:4)

更改

double = radius;

double radius = 0;

并删除;方法定义后的public static void main(String[] args);

,在double radius = in.nextDouble();语句中,您必须删除double关键字,因为您已经定义了一个具有相同名称的变量。

答案 1 :(得分:3)

您的代码有三个问题:

删除main方法声明中的分号。

public static void main(String[] args)

您的第二个问题是您没有双变量的参考。所有变量都必须有引用。考虑一下应该是的代码:

double radius = 0;

double 是数据类型, radius 是参考。换句话说,double是变量的类型,radius是变量的名称。

你的第三个问题是这一行。

double radium = in.nextDouble();

您应将其更改为:

radius = in.nextDouble();

必须正确引用所有变量。此外,通过再次声明变量,您将隐藏旧变量。


最好不要初始化变量然后再次初始化它,删除你的行:

double = radius

或如果您将其更改为我上面所述,请删除

double radius = 0;

答案 2 :(得分:1)

删除';'来自你的主要

public static void main(String[] args);

public static void main(String[] args)

答案 3 :(得分:0)

你的变量声明很混乱:double = radius;没有意义,因为double是一个类型,而不是一个变量(变量声明看起来像type identifier = value;而不是type = identifier;或者identifier = type;),您声明但从不使用radium变量。应该是这样的:

Scanner in = new Scanner(System.in);
System.out.print("Radius of circle (cm) :> ");
double radius = in.nextDouble();
System.out.print("Area of circle :> " + Math.PI * Math.pow(radius,2));
System.out.print("Circumference of circle :> " + 2 * Math.PI * radius);
System.out.print("Surface area the sphere with that radius :> " + 4 * Math.PI * Math.pow(radius,2));
System.out.print("Volume of sphere with that radius :> " + 4/3 * (radius * Math.pow(radius,2)));

您不应该在;方法声明行的末尾添加main

答案 4 :(得分:0)

罪魁祸首(即声明变量的错误方式):

  

double = radius;

应该是这种形式的东西:

  

double radius = 0;

但是,我看到你再次使用radius,但这次正确地,从控制台获取用户输入的值,这样你就可以安全地删除罪魁祸首语句,它应该可以工作。

答案 5 :(得分:0)

您拥有的代码:

import java.util.Scanner;
import static java.lang.Math;

public class Formula
{
public static void main(String[] args);
{
double = radius;

    Scanner in = new Scanner(System.in);
    System.out.print("Radius of circle (cm) :> ");
    double radius = in.nextDouble();
    System.out.print("Area of circle :> " + Math.PI * Math.pow(radius,2));
    System.out.print("Circumference of circle :> " + 2 * Math.PI * radius);
    System.out.print("Surface area the sphere with that radius :> " + 4 * Math.PI * Math.pow(radius,2));
    System.out.print("Volume of sphere with that radius :> " + 4/3 * (radius * Math.pow(radius,2)));

    }
}

应该是什么样的:

import java.util.Scanner;
import static java.lang.Math;

public class Formula
{
public static void main(String[] args) {

double radius = 0;

    Scanner in = new Scanner(System.in);
    System.out.print("Radius of circle (cm) :> ");
    radius = in.nextDouble();
    System.out.print("Area of circle :> " + Math.PI * Math.pow(radius,2));
    System.out.print("Circumference of circle :> " + 2 * Math.PI * radius);
    System.out.print("Surface area the sphere with that radius :> " + 4 * Math.PI * Math.pow(radius,2));
    System.out.print("Volume of sphere with that radius :> " + 4/3 * (radius * Math.pow(radius,2)));

    }
}

你的方法后面有一个分号,声明双重需要等于某个东西,你不需要说 double radius = in.nextDouble(); 你只需要 radius = in.nextDouble();