[英]Repeated JOptionPane pop-up?
so I'm writing a program that gives the number of minutes for every input of x seconds... now the issue is that once I type in the first value, it asks for another value and divides that....and another value...and another...and so on... how can I get it to only give me one value and finish with that one value instead of a never-ending thing?所以我正在编写一个程序,该程序给出每次输入 x 秒的分钟数……现在的问题是,一旦我输入第一个值,它就会要求输入另一个值并将其除以……和另一个值......还有另一个......等等......我怎样才能让它只给我一个价值并以那个价值结束而不是一个永无止境的东西?
import javax.swing.JOptionPane;
class TimeCalculator {
public static void main(String[] args) {
double seconds;
String input;
input = JOptionPane.showInputDialog("Enter any number of seconds");
seconds = Double.parseDouble(input);
if (seconds >= 60);
JOptionPane.showInputDialog(null, "There are " + (seconds/60) + " minutes in " + seconds + " seconds.");
if (seconds >= 3600);
JOptionPane.showInputDialog(null, "There are " + (seconds/60) + " minutes in " + seconds + " seconds.");
if (seconds >= 86400);
JOptionPane.showInputDialog(null, "There are " + (seconds/60) + " minutes in " + seconds + " seconds.");
System.exit(0);
}
}
First of all - remove the semicolons after each if
statement.首先 - 删除每个
if
语句后的分号。 Secondly, change the showInputDialog
to showMessageDialog
when you are not asking for input.其次,改变
showInputDialog
到showMessageDialog
当你不要求输入。 Thirdly, correct the logic of your code:第三,更正代码的逻辑:
class TimeCalculator{
public static void main(String[] args) {
double seconds;
String input;
input = JOptionPane.showInputDialog("Enter any number of seconds");
seconds = Double.parseDouble(input);
if (seconds >= 60)
JOptionPane.showMessageDialog(null, "There are " + (seconds / 60) + " minutes in " + seconds + " seconds.");
if (seconds >= 3600)
JOptionPane.showMessageDialog(null, "There are " + (seconds / 3600) + " hours in " + seconds + " seconds.");
if (seconds >= 86400)
JOptionPane.showMessageDialog(null,
"There are " + (seconds / 86400) + " days in " + seconds + " seconds.");
System.exit(0);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.