所以我想编写一个应用程序来读取表示小时,分钟和秒的时间的值。然后在几秒钟内打印相同的时间。 (例如,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");
}
}
答案 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)