import java.util.Scanner;
import javax.swing.*;
@SuppressWarnings("serial")
public class Synthetic_Division extends JFrame{
public void init(){
JTextField JTF = new JTextField();
JLabel label = new JLabel();
JPanel panel = new JPanel();
panel.add(label);
panel.add(JTF);
this.add(panel);
}
public Synthetic_Division(){
super("Synthetic Division");
this.init();
this.setSize(600, 400);
this.setVisible(true);
}
public static void main(String[] args) {
int sol01 = 0, sol12 = 0, sol23 = 0, sol34 = 0, sol45 = 0, cross12 = 0, cross23 = 0, cross34 = 0, cross45 = 0, cross56 = 0, Remainder = 0, Divisor = 0, Number1 = 0, Number2 = 0, Number3 = 0, Number4 = 0, Number5 = 0, Number6 = 0, NumberOfNumbers = 0;
System.out.println("Please input the following values accordingly.");
System.out.println("1. Numbers in equation (: 4-6 :)");
System.out.println("2. Divisor (: After the sign has been flipped :)");
System.out.println("3. First Number");
System.out.println("4. Second Number");
System.out.println("5. Third Number");
System.out.println("6. Fourth Number");
System.out.println("7. Fifth Number (: If Needed :)");
System.out.println("8. Sixth Number (: If Needed :)");
Scanner in = new Scanner(System.in);
NumberOfNumbers = in.nextInt();
Divisor = in.nextInt();
Number1 = in.nextInt();
Number2 = in.nextInt();
Number3 = in.nextInt();
Number4 = in.nextInt();
if (NumberOfNumbers == 5 || NumberOfNumbers == 6) {
Number5 = in.nextInt();
}
if (NumberOfNumbers == 6) {
Number6 = in.nextInt();
}
if (NumberOfNumbers == 4) {
sol01 = Number1;
cross12 = sol01 * Divisor;
sol12 = Number2 + cross12;
cross23 = sol12 * Divisor;
sol23 = Number3 + cross23;
cross34 = sol23 * Divisor;
Remainder = Number4 + cross34;
if (Remainder == 0) {
System.out.println(sol01 + " + " + sol12 + " + " + sol23
+ " with no remainder! ");
} else {
System.out.println(sol01 + " + " + sol12 + " + " + sol23
+ " with a remainder of: " + Remainder);
}
} else if (NumberOfNumbers == 5) {
sol01 = Number1;
cross12 = sol01 * Divisor;
sol12 = Number2 + cross12;
cross23 = sol12 * Divisor;
sol23 = Number3 + cross23;
cross34 = sol23 * Divisor;
sol34 = Number4 + cross34;
cross45 = sol34 * Divisor;
Remainder = Number5 + cross45;
if (Remainder == 0) {
System.out.println(sol01 + " + " + sol12 + " + " + sol23 + " + "
+ sol34 + " with no remainder! ");
} else {
System.out.println(sol01 + " + " + sol12 + " + " + sol23
+ " + " + sol34 + " with a remainder of: " + Remainder);
}
} else if (NumberOfNumbers == 6) {
sol01 = Number1;
cross12 = sol01 * Divisor;
sol12 = Number2 + cross12;
cross23 = sol12 * Divisor;
sol23 = Number3 + cross23;
cross34 = sol23 * Divisor;
sol34 = Number4 + cross34;
cross45 = sol34 * Divisor;
sol45 = Number5 + cross45;
cross56 = sol45 * Divisor;
Remainder = Number6 + cross56;
if (Remainder == 0) {
System.out.println(sol01 + " + " + sol12 + " + " + sol23 + " + "
+ sol34 + " + " + sol45 + " with no remainder! ");
} else {
System.out.println(sol01 + " + " + sol12 + " + " + sol23
+ " + " + sol34 + " + " + sol45
+ " with a remainder of: " + Remainder);
}
} else {
System.out.println("Please input correct number of numbers");
}
}
}
出於某種原因,當我運行此代碼時,沒有GUI顯示,但有一個程序開始運行,我可以隨時停止。正如你可能通過代碼所說的那樣,我對Java來說是個新手。我只是添加了其餘的代碼,希望對故障排除有所幫助,但我仍然沒有將GUI實現到主類中,因爲我想查看GUI是否是我想要的第一個。Java GUI沒有顯示
你的main() – TwilightSun