Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java程序只输出一行代码_Java_Fileinputstream_Fileoutputstream - Fatal编程技术网

Java程序只输出一行代码

Java程序只输出一行代码,java,fileinputstream,fileoutputstream,Java,Fileinputstream,Fileoutputstream,我的类的java程序有问题。我必须创建一个程序,提示用户输入输出文件的路径和名称,该文件将包含我的程序将采用的方程的系数行,并使用二次公式计算解。到目前为止,除了我的输出文件外,我认为一切都是正确的。假设我有一个包含3行系数的输入文件,我的程序将在控制台流中显示解决方案,但在输出文件中只显示1行解决方案 while (input.hasNext()) { a = input.nextInt(); b = input.nextInt(); c = input.nextIn

我的类的java程序有问题。我必须创建一个程序,提示用户输入输出文件的路径和名称,该文件将包含我的程序将采用的方程的系数行,并使用二次公式计算解。到目前为止,除了我的输出文件外,我认为一切都是正确的。假设我有一个包含3行系数的输入文件,我的程序将在控制台流中显示解决方案,但在输出文件中只显示1行解决方案

while (input.hasNext()) {

    a = input.nextInt();
    b = input.nextInt();
    c = input.nextInt();

    discriminant = Math.pow(b, 2) - 4 * a * c;
    ///There will be no solutions if discriminant<0
    if (discriminant < 0){
        System.out.println("There are no solutions.");
        output.println("There are no solutions.");
    }
    ///As with the above, if coefficent a = 0 no solutions
    else if (a == 0){
        System.out.println("There are no solutions.");
        output.println("There are no solutions.");
    }
    else if (discriminant == 0){
       solutionOne = (-b + Math.sqrt(discriminant)) / (2 * a);
       if (b < 0) {
           System.out.printf("%3.0fx^2 %3.0fx + %3.0f, has one      solution:%5.3f%n",a,b,c,solutionOne);
           output.printf("%3.0fx^2 %3.0fx + %3.0f has one solution:%5.3f%n",a,b,c,solutionOne);
        }
       else{
           System.out.printf("%3.0fx^2 %3.0fx + %3.0f has one  solution:%5.3f%n",a,b,c,solutionOne);
           output.printf("%3.0fx^2 %3.0fx + %3.0f has one solution:%5.3f%n",a,b,c,solutionOne);
       }

    }
       else if(discriminant>0){
           solutionOne=(-b + Math.sqrt(discriminant))/(2*a);
           twoSolutions=(-b - Math.sqrt(discriminant))/(2*a);

           if(b<0){
               System.out.printf("%3.0fx^2 %3.0fx + %3.0f has two solutions: %5.3f %5.3f%n",a,b,c,solutionOne,twoSolutions);
               output.printf("%3.0fx^2 %3.0fx + %3.0f has two solutions:5.3f %5.3f%n",a,b,c,solutionOne,twoSolutions);
           }

           else{

           System.out.printf("%3.0fx^2 %3.0fx + %3.0f has two solutions:%5.3f %5.3f%n",a,b,c,solutionOne,twoSolutions);
           output.printf("%3.0fx^2 %3.0fx + %3.0f has two solutions: %5.3f%5.3f%n",a,b,c,solutionOne,twoSolutions);
           }

    }

    output.close();

如果我没看错你的括号,问题是你在打电话

output.close();
在循环的每个迭代结束时。在编写完所有输出之后,需要在循环外部调用它