Java 处理多个数组并返回值

Java 处理多个数组并返回值,java,Java,我一直在开发一个程序,要求用户输入电路的值,然后计算给定时间的电荷。我已经取得了一些进展,但当我的一个数组拒绝返回值时,我遇到了一个障碍,eclipse中提到的原因是: *这条线上有多个标记 Ass1类型中的方法genQArray(int[],int,double[],int,int,int,int)不适用于参数(int[],int,double,int,int, int,int) Ass1类型中的方法genQArray(int[],int,double[],int,int,int,int)不

我一直在开发一个程序,要求用户输入电路的值,然后计算给定时间的电荷。我已经取得了一些进展,但当我的一个数组拒绝返回值时,我遇到了一个障碍,eclipse中提到的原因是:

  • *这条线上有多个标记
  • Ass1类型中的方法genQArray(int[],int,double[],int,int,int,int)不适用于参数(int[],int,double,int,int, int,int)
  • Ass1类型中的方法genQArray(int[],int,double[],int,int,int,int)不适用于参数(int[],int,int)*
老实说,我不知道这一点上的问题是什么,我想找到一个解决办法,所以我可以继续这个计划的工作。非常感谢您的帮助

以下是我的代码,尽管它尚未完成:

import java.util.* ;
public class Ass1 {

    static int VIX ; // Traversing Voltage Component in Component Value Array 
    static int CIX ; 
    static int LIX ; 
    static int RIX ; 

    public static void main (String args[]) { 
        double compArr  = getCircuitComp() ; 
        boolean outerLoopFlag ; 
        boolean innerLoopFlag ; 
        int i ; 
        int n ;
        int timeArr[] = new int[n] ; 
        int qArray[] = new int[n] ;
        Scanner input = new Scanner (System.in) ;
        while ( outerLoopFlag = true) { 

            System.out.print("Reset Component Values (y/n) ?") ; 
            String answer = input.nextLine() ; 
            char ans = answer.charAt(0) ;  
            if ( ans == 'y') { 
                compArr = getCircuitComp() ; 

            } 
            else { 
                    } 
            innerLoopFlag = true ; 
            while ( innerLoopFlag = true){ 
                System.out.print("Run a simulation?") ; 
                String answer2 = input.nextLine() ; 
                char ans2 = answer.charAt(0) ; 
                if (ans2 == 'y'){
                System.out.print("Enter a maximum time :") ; 
                double tMax = input.nextDouble(); 
                System.out.print("Enter a time step:") ; 
                double tStep = input.nextDouble();
                timeArr[n]= genTimeArray(tMax,tStep,n);  
                qArray[n] = genQArray( timeArr , n , compArr,  VIX ,  CIX ,  RIX ,  LIX) ;  
                displayQFunction(timeArr,qArray,n);

                }

                while (innerLoopFlag = false) { 
                    System.out.print("Do you want to quit (y/n)?") ;
                    String answer3 = input.nextLine() ; 
                    char ans3 = answer3.charAt(0) ; 

                }


            }   



    }

}

    public static int getCircuitComp() {
        Scanner input = new Scanner (System.in) ; 
        boolean flag = true ; 
        double compArr [] = new double[4]; 
        while (  flag = true ) { 
            System.out.print("Enter a value V ( 4 to 15):") ; 
            compArr[VIX] = input.nextDouble() ;  
            if ((compArr[VIX] >= 4.0) && (compArr[VIX] <= 15.0)){ 
                flag = false ; 
            }
            else{ 
                System.out.print("Bad Value" + compArr[VIX] ) ;
            }

        }
        flag = true  ; 
        while (flag) { 
            System.out.print("Enter a valur for R ( 5 to 10) :") ; 
            compArr[RIX] = input.nextDouble();  
            if((compArr[RIX] >= 5.0) && (compArr[RIX] <= 10.0)){
flag = false;
            }
            else{
                System.out.print("Bad Value:"+ compArr[RIX]) ; 

            }

        }
            flag = true ; 
            while(flag) { 
                System.out.print("Enter a value for C( 1e-9 to 1e-7 ): ") ; 
                compArr[CIX] = input.nextDouble();  
                if (( compArr[CIX] >= Math.pow(10, -9)) && (compArr[CIX] <= Math.pow(10, -7))){
                    flag = false ; 
                }
                else{ 
                    System.out.print("Bad Value :"+ compArr[CIX]);
                }


            }
                flag = true ; 
                while(flag){ 
                    System.out.print("Enter a value for L(1e-3 to 1e-1) "); 
                    compArr[LIX] = input.nextDouble(); 
                    if(compArr[LIX]>= Math.pow(10,-3) && compArr[LIX] <= Math.pow(10, -1)){
                        flag = false ; 
                    }
                    else{ 
                        System.out.print("Bad Value :" + compArr[LIX]) ; 

                    }
                }
                return (int) (compArr[CIX] + compArr[LIX] + compArr[RIX] + compArr[VIX]) ;  
            }


        public static int genTimeArray( double tMax , double tStep , int n ) { 
             int t[] = new int[n] ;
             n = 1 ; 
             t[0] = 0 ; 
             t[n] = (int) (t[n-1] + tStep) ; 
             n = n + 1 ; 

            return t[n] ;

        } 
        public static int genQArray( int timeArr[] , int n , double compArr [], int VIX , int CIX , int RIX , int LIX ) {
            double q[] = new double[n] ; 
            n = 1 ;  
            double s = (compArr[VIX])*(compArr[CIX]) ; 
            double t = Math.exp((-compArr[RIX])/(2*compArr[LIX])); 
            double c = (1)/((compArr[LIX])*(compArr[CIX])) ; 
            double v = Math.pow((compArr[RIX])/(2*(compArr[LIX])),2) ;
            double r = (timeArr[n])*(Math.sqrt(c-v)) ;
            q[n] = (s)*(t)*(Math.cos(r)) ; 

            return (int) q[n] ;


        }

    } 
import java.util.*;
公共课助理1{
static int VIX;//遍历元件值数组中的电压元件
静态int-CIX;
静态int-LIX;
静态整数;
公共静态void main(字符串args[]){
双比较器=getCircuitComp();
布尔outerLoopFlag;
布尔内环标志;
int i;
int n;
int timeArr[]=新的int[n];
int qArray[]=新的int[n];
扫描仪输入=新扫描仪(System.in);
而(outerLoopFlag=true){
系统输出打印(“重置组件值(y/n)?”;
字符串answer=input.nextLine();
char ans=答案charAt(0);
如果(ans=='y'){
compArr=getCircuitComp();
} 
否则{
} 
innerLoopFlag=true;
而(innerLoopFlag=true){
System.out.print(“运行模拟?”);
字符串answer2=input.nextLine();
char ans2=答案.charAt(0);
如果(ans2='y'){
System.out.print(“输入最长时间:”);
double tMax=input.nextDouble();
System.out.print(“输入时间步长:”);
double tStep=input.nextDouble();
timeArr[n]=genTimeArray(tMax,tStep,n);
qArray[n]=genQArray(timeArr,n,compArr,VIX,CIX,RIX,LIX);
显示Qfunction(timeArr、qArray、n);
}
while(innerLoopFlag=false){
System.out.print(“是否要退出(y/n)”;
字符串answer3=input.nextLine();
char ans3=answer3.charAt(0);
}
}   
}
}
公共静态int getCircuitComp(){
扫描仪输入=新扫描仪(System.in);
布尔标志=真;
双比较器[]=新的双比较器[4];
while(flag=true){
系统输出打印(“输入值V(4到15):”;
compArr[VIX]=input.nextDouble();

如果((compArr[VIX]>=4.0)&&(compArr[VIX]=5.0)&(compArr[RIX]=Math.pow(10,-9))&&(compArr[CIX]=Math.pow(10,-3)&&compArr[LIX]您将需要从

double compArr  = getCircuitComp() ; 

要正确匹配方法
genQArray
的参数,需要从
getCircuitComp()
返回
double[]
,而不是
int
类型

public static double[] getCircuitComp() {
在这个方法中,您可能想要返回变量:

double compArr [] = new double[4]; 
还请注意,您的变量:

static int VIX ; 
static int CIX ; 
static int LIX ; 
static int RIX ; 
将全部默认为
0
,因此,例如,
compArr[VIX]
compArr[CIX]
将指向数组
compArr
中索引0处的相同值。若要修复,可以指定值:

static int VIX = 0; 
static int CIX = 1; 
...

Reimeus,我一输入就收到了另一个错误:类型不匹配:无法从double转换为double[],并且有一个错误声明:“此行有多个标记-compArr无法解析为类型-标记“]”上的语法错误,VariableDeclaratorId应位于该标记之后“正如我所说的,您必须返回一个
double[]
from
getCircuitComp()
不是一个
int
。第二个错误看起来像是一个伪字符。祝你好运!谢谢Reimeus,尽管我仍在为如何消除第一个错误而困惑;我已经尝试将它改为双精度,我尝试了所有其他方法,但我仍然收到了该消息。这应该是一个
double[]
。已使用方法的新签名进行更新。您将根据代码返回单个值;但与上面的相反,您希望使用双数组
static int VIX = 0; 
static int CIX = 1; 
...