最佳拟合直线
问题:输出有问题,算法目前无问题
package kl;
import java.util.Scanner;
class Sum{//此类无用,在循环中无法输入数据
int x,y;
double a,b;//输入数据需改进
double f(double s1,double s2,double s3,double s4,int n) {
return a;
}
double f1(double s1,double s2,double s3,double s4,int n) {
return b;
}
}
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
double a,b,s1 = 0,s2 = 0,s3 = 0,s4 = 0;
for(int i = 0; i < n;i++) {
double x = in.nextDouble();
double y = in.nextDouble();
s1 = s1 + xy;
s2 = s2 + x;
s3 = s3 + y;
s4 = s4 + xx;
}
a = (n s1 - s2s3)/(ns4 - s2s2);
b = (s3s4 - s2 s1)/(ns4 - s2s2);
System.out.printf("%.3lf%n",a);//输出有问题,在printf 上
System.out.printf("%.3lf\n",b);
}
}