为什么Java告诉我'a'是预期的,非法的表达开始?

时间:2013-09-26 00:02:01

标签: java

所以我想编写一个应用程序来读取表示小时,分钟和秒的时间的值。然后在几秒钟内打印相同的时间。 (例如,1小时28分42秒等于5322秒。)我使用JCreator,当我尝试编译时,它告诉我第21行有2个错误,这是 System.out.println(“你的答案等于=”+时间“秒”); 而且它告诉我的错误是')'是预期的和非法的表达开始。

 import java.util.Scanner;
    public class StackOverflow.swag // for teh lulz
    {
        public static void main (String [] args);
        {
            double time, hours, minutes, seconds;
            seconds = 0.0;
            minutes = minutes*3600;
            hours = hours*216000;
            time = seconds+minutes+hours;
            Scanner scan = new Scanner (System.in);

            System.out.println ("Enter number of hours");
            hours = scan.nextDouble();
            System.out.println ("Enter number of minutes");
            minutes = scan.nextDouble();
            System.out.println ("Enter number of seconds");
            seconds = scan.nextDouble();


            System.out.println ("Your answer equals =" +time+ "seconds");


        }
    }

1 个答案:

答案 0 :(得分:6)

您在+time之间错过了"seconds"。变化

System.out.println ("Your answer equals =" +time "seconds");

System.out.println ("Your answer equals =" + time + "seconds");

此外,在您的main方法签名后,语法不正确会有分号。变化

public static void main (String [] args);

public static void main (String [] args)