2011-06-30 27 views
0

私は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 

です:あなたが前に+記号を追加する必要がseconds2minuteshoursの各後

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 

答えて

4

と二重引用符。

0

エラーメッセージは少しトリッキーです。実際の問題はここにあります:

秒2秒。 は

2

(2つの変数の間行方不明「+」記号があります)、このようになります。

"That will be " + hours + "hours, " + minutes + "minutes, and " + seconds2 + "seconds." 
+0

ありがとうございます!それが問題を解決しました! :-) – user820913