import java.util.Scanner;
public class Main {
static double a, b, c, x, y, AOS;
public static void main(String[] args) {
Main.getA();
}
public static void getA() {
Scanner inputA = new Scanner(System.in);
System.out.println("Input variable 'a'");
a = inputA.nextDouble();
inputA.close();
System.out.println("A: " + a);
Main.getB();
}
public static void getB() {
Scanner inputB = new Scanner(System.in);
System.out.println("Input variable 'b'");
b = inputB.nextDouble();
inputB.close();
System.out.print("B: " + b);
Main.getC();
}
public static void getC() {
Scanner inputC = new Scanner(System.in);
System.out.println("Input variable 'c'");
c = inputC.nextDouble();
inputC.close();
System.out.print("C: " + c);
Main.getAOS();
}
public static void getAOS() {
AOS = (-b + Math.sqrt((b*b)-4*a*c))/2*a;
System.out.println("AOS: " + AOS);
Main.getPoint1();
}
public static void getPoint1() {
x = AOS;
y = (a*(x*x)) + (b*x) + c;
System.out.println("Origin: (" + x + "," + y + ")");
Main.getPoint2();
}
public static void getPoint2() {
x = AOS + 1;
y = (a*(x*x)) + (b*x) + c;
System.out.println("1: (" + x + "," + y + ")");
Main.getPoint3();
}
public static void getPoint3() {
x = AOS - 1;
y = (a*(x*x)) + (b*x) + c;
System.out.println("2: (" + x + "," + y + ")");
Main.getPoint4();
}
public static void getPoint4() {
x = AOS + 2;
y = (a*(x*x)) + (b*x) + c;
System.out.println("3: (" + x + "," + y + ")");
Main.getPoint5();
}
public static void getPoint5() {
x = AOS - 2;
y = (a*(x*x)) + (b*x) + c;
System.out.println("4: (" + x + "," + y + ")");
}
}
這是我的代碼。我正在嘗試獲取用戶輸入以選擇變量a,b和c的值,以便程序可以運行方程式。數學可行,但在第一次輸入後出現錯誤。使用用戶輸入聲明Java中變量的變量
你的錯誤是什麼? – CubeJockey
關閉後無法從System.in中讀取。即使你創建了一個新的'Scanner'指向它,你已經關閉了流。 – azurefrog