的输出数据是从1显示max
,每行一个有以下例外:触发器号码检查
- 数整除
a
被替换为单词“翻转” - 数通过
b
整除被替换为 - 号双方整除由“触发器” 012一词改为 “翻牌”
我被卡住了,需要一个小方向来解决我的问题。我想也许for
循环将是完美的通过和列出数字,并有if else
检查每个数字与用户选择的输入数字。
import javax.swing.JOptionPane;
public class FlipFlop {
public static void FlipFlop(Integer a, Integer b, Integer Max) {
for (int i = 1; i < Max; i++) {
if (i % a == 0) {
System.out.println("Flip");
} else if (i % b == 0) {
System.out.println("Flop");
} else if (i % a == 0 && i % b == 0) {
System.out.println("FlipFlop");
} else {
System.out.println(i);
}
System.out.println();
}
}
public static void main(String[] arg) {
Integer a;
Integer b;
Integer max;
String Title = "FlipFlop Assignment";
String data = JOptionPane.showInputDialog(null, "Enter your first number", Title, 1);
a = new Integer(data);
data = JOptionPane.showInputDialog(null, "Enter your second number", Title, 1);
b = new Integer(data);
data = JOptionPane.showInputDialog(null, "Enter the upper bound", Title, 1);
max = new Integer(data);
FlipFlop(a, b, max);
}
}
请[edit]添加一个特定的问题陈述 - “它不起作用”可以假设,但* how *不起作用?什么错误信息或不正确的行为是特征? –
同上。你遇到了什么错误? – xdhmoore
对不起!它无法在for循环中找到“max”整数的符号。最大符号是用户输入的整数。 – Eagles11