geradengleichung.java 913 B

12345678910111213141516171819202122232425262728293031323334
  1. import java.util.Arrays;
  2. import javax.swing.table.*;
  3. import java.lang.Math;
  4. public class geradengleichung {
  5. static void errorExit(String errorMsg) {
  6. System.out.println("Error: " + errorMsg);
  7. System.exit(1);
  8. }
  9. public static void main(String args[]) {
  10. if (args.length != 4) {
  11. errorExit("please provide 4 commandline arguments");
  12. }
  13. int Px = 0, Py = 0, Qx = 0, Qy = 0;
  14. try {
  15. Px = Integer.parseInt(args[0]);
  16. Py = Integer.parseInt(args[1]);
  17. Qx = Integer.parseInt(args[2]);
  18. Qy = Integer.parseInt(args[3]);
  19. } catch (NumberFormatException e) {
  20. errorExit("please only provide integer input");
  21. }
  22. double delta_y = Math.abs(Py-Qy);
  23. double delta_x = Math.abs(Px-Qx);
  24. double a = delta_y / delta_x;
  25. double b = Math.min(Py, Qy);
  26. System.out.printf("f(x) = %fx + %f\n", a, b);
  27. }
  28. }