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
After each of
hours,minutesandseconds2you need to add a+sign before the double quotes.