为什么Java告诉我a';)';表达式的开头是否非法?
因此,我假设编写一个应用程序,读取以小时、分钟和秒为单位的时间值。然后以秒为单位打印相同的时间。(例如,1小时28分42秒等于5322秒)我使用JCreator,当我尝试编译时,它告诉我在第21行有2个错误,这是为什么Java告诉我a';)';表达式的开头是否非法?,java,Java,因此,我假设编写一个应用程序,读取以小时、分钟和秒为单位的时间值。然后以秒为单位打印相同的时间。(例如,1小时28分42秒等于5322秒)我使用JCreator,当我尝试编译时,它告诉我在第21行有2个错误,这是 System.out.println(“您的答案等于=”+时间“秒”); 它告诉我的错误是“')是表达式的预期和非法开始 import java.util.Scanner; public class StackOverflow.swag // for teh lulz
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");
}
}
在
时间
和秒之间缺少+
。改变
System.out.println ("Your answer equals =" +time "seconds");
到
另外,在main
方法签名后还有一个分号,语法不正确。改变
public static void main (String [] args);
到
当我这样做时,它会在第行告诉我“缺少方法体,或者声明抽象”4@Sam分号不应该在那里;看我更新的答案。是的,我这么做了,但后来我意识到我也过早地设置了变量的值,所以我现在就让它工作了。
public static void main (String [] args);
public static void main (String [] args)