二次公式是错误的,我不知道如何修复

时间:2015-09-28 23:44:47

标签: java drjava

错误:

File: F:\lab_2.java  [line: 36]
Error: next cannot be resolved or is not a field
File: F:\lab_2.java  [line: 38]
Error: next cannot be resolved or is not a field
File: F:\lab_2.java  [line: 40]
Error: next cannot be resolved or is not a field
File: F:\lab_2.java  [line: 42]
Error: Duplicate local variable outa 

代码:

   else if (choice==1){
          int a;
          int b;
          int c;
          System.out.println("what is a ?");
          a=myscan.next ;   //line 36
          System.out.println("what is b ?");
          b=myscan.next ;   //line38
          System.out.println("what is c ?");
          c=myscan.next ;   //line40
       double outa =(b + Math.sqrt((b*b)-4*a*c))/(2*a);
       double outa =(b - Math.sqrt((b*b)-4*a*c))/(2*a);   //line42
       }
          //quadratic formula ^^^^

1 个答案:

答案 0 :(得分:1)

错误意味着“next”不是变量myscan上的有效方法或字段,我假设它是一个扫描程序。 如果“myscan”是一个扫描仪,我认为你正在寻找输入,所以:

a=myscan.nextInt();

另外,你将b +和b-分配给outa,所以你用第二个答案覆盖第一个答案。