什么" .class预期错误"在java中意思

时间:2014-10-18 08:21:38

标签: java

这是我的代码。我得到一个错误“.class expected”。 我该怎么做才能纠正它。

import java.util.*;
class Atm2
{
    public static void main (String args[])
    {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the amount to be withdrawed");
        int withdraw = in.nextInt();
        System.out.println("Enter the amount in the account");
        double acnt_balc = in.nextDouble();
        if ((withdraw % 5 == 0) && (acnt_balc >= withdraw + 0.50))
            double cur = acnt_balc - (withdraw + 0.50);
            System.out.println(cur);
        else
            System.out.println(acnt_balc);
    }
}

2 个答案:

答案 0 :(得分:1)

在if-else的上下文中尝试大括号。 它应该是这样的:

if (isMoving) {
    currentSpeed--;
} else {
    System.err.println("The bicycle has already stopped!");
} 

所以你可以看到,有一个if-block和一个else-block。你必须说哪个代码属于if,哪个代码属于else。你可以用大括号做到这一点。

答案 1 :(得分:-1)

扫描仪要求您导入java.util。*;

我尝试了它并且格式正确,见下文,它运行

import java.util.*;

    class Atm2

        {
            public static void main (String args[])
            {
                Scanner in = new Scanner(System.in);
                System.out.println("Enter the amount to be withdrawed");
                int withdraw = in.nextInt();
                System.out.println("Enter the amount in the account");
                double acnt_balc = in.nextDouble();
                if ((withdraw % 5 == 0) && (acnt_balc >=(withdraw + 0.50)))
                {
                 double cur=(acnt_balc-(withdraw + 0.50));
                    System.out.println(cur);
                }
                else
                {
                    System.out.println(acnt_balc);
                }
            }
        }

还要确保您的文件名与类名相同,在本例中为Atm2.java

“java.util”包中存在的扫描程序类,因为您忘记导入它并使用了Scanner sc = new Scanner(); compliler抱怨,并记得编译使用javac filename.java,运行使用java文件名