错误消息:´)´预期,并且“不是声明” ´;´预计
我对 Java 编程完全陌生,并且自己学习了一些基本教程。 我正在尝试解决一个练习,它告诉我制作一个小程序,用户在其中输入几秒钟。然后程序应该返回这是多少小时、分钟和秒。我无法摆脱错误消息。有人可以帮我吗? 我的代码如下,
import javax.swing.JOptionPane;
public class Time2
{
public static void main( String args[] )
{
// Defining types of data:
String secondstring;
int minutes;
int seconds;
int hours;
int seconds1;
int seconds2;
// Making inputwindow and initializing the variable sekondstring:
secondstring = JOptionPane.showInputDialog( "Type in seconds!" );
// Converting secondstring to type int:
seconds = Integer.parseInt( secondstring );
// Initializing the variables seconds, minutes and hour:
hours = seconds / 3600;
seconds1 = seconds % 3600;
minutes = seconds1 / 60;
seconds2 = seconds1 % 60;
// Making output box:
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
} // End of main method.
} // End of class Time2
当我尝试编译时收到以下错误消息:
Time2.java:28: ')' expected
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: not a statement
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: ';' expected
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: not a statement
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: ';' expected
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: not a statement
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: ';' expected
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
7 errors
I´m totally new to programming in java, and following some basic tutorials for my self.
I´m trying to solve an excercise wich tells me to make a small program where the user types in an amonunt of seconds. The program is then supposed to return how many hours, minutes and seconds this is. I can´t get ridd of the error messages. Can anyone help me please?
My code is the following
import javax.swing.JOptionPane;
public class Time2
{
public static void main( String args[] )
{
// Defining types of data:
String secondstring;
int minutes;
int seconds;
int hours;
int seconds1;
int seconds2;
// Making inputwindow and initializing the variable sekondstring:
secondstring = JOptionPane.showInputDialog( "Type in seconds!" );
// Converting secondstring to type int:
seconds = Integer.parseInt( secondstring );
// Initializing the variables seconds, minutes and hour:
hours = seconds / 3600;
seconds1 = seconds % 3600;
minutes = seconds1 / 60;
seconds2 = seconds1 % 60;
// Making output box:
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
} // End of main method.
} // End of class Time2
I get the following error-message when I try to compile:
Time2.java:28: ')' expected
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: not a statement
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: ';' expected
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: not a statement
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: ';' expected
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: not a statement
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
Time2.java:28: ';' expected
JOptionPane.showMessageDialog( null, "That will be " + hours "hours, " + minutes "minutes, and " + seconds2 "seconds.", "Result", JOptionPane.PLAIN_MESSAGE );
^
7 errors
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在每个
小时
、分钟
和秒2
之后,您需要在双引号前添加一个+
符号。After each of
hours
,minutes
andseconds2
you need to add a+
sign before the double quotes.应该是这样的:
should be this:
错误消息有点棘手。真正的问题在这里:
seconds2“秒”。
(两个变量之间缺少一个“+”号)
The error-message is a little bit tricky. The real problem is here:
seconds2 "seconds."
(there is a missing "+" sign between the two variables)