Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Anyone here good at (very basic) Java?
#1
I'm beginning to learn Java, but now I'm stuck at a task. I'm writing a program where the user writes in x seconds. The program then converts it into hours, mintes and seconds.
So this is my code, and I'm not sure what's wrong (likely something with the division of seconds.

import static javax.swing.JOptionPane
public class Tidsberegning2 {
       public static void main(String[] args) {
                String secondsRead = showInputDialog("Seconds: ");
                int seconds = Integer.parseInt(secondsRead) ;
                double answer1 = seconds/3600;
                double answer2 = seconds/60;
                double answer3 = seconds%60
                showMessageDialog(null, "Answer: " + answer1 + "hours, " + answer2 + "minutes and " + answer3 + "seconds");
      } 
}
[Image: 2is88j5.png]
Reply
#2
(2019-08-30 08:13:36)Podifo Wrote: double answer2 = seconds%60
this variable should probs be named answer3
[Image: tumblr_nddxf2XzYY1tvf9p0o1_400.gif]
Reply
#3
Ignore that, it says answer3 in my code
[Image: 2is88j5.png]
Reply
#4
is there an actual error message?
[Image: tumblr_nddxf2XzYY1tvf9p0o1_400.gif]
Reply
#5
Nope, and I found out what I did wrong
[Image: 2is88j5.png]
Reply
#6
Generally when you ask a question like this you should also post how you know that it's wrong. So either what you put in, what you expected, and what you actually got, or an error message.
Reply




Users browsing this thread: 1 Guest(s)