Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

java - I'm using two for loops and wants 25 "i"(inner loop) values w.r.t the "j" or X[] values.but it shows something different.plz help me

I'm using two for loops and wants 25 "i"(inner loop) values w.r.t the "j" or X[] values.but it shows something different.plz help me. this is my code

  int X[] = {1,2,3,5,10,20,30,40};
  for(int j=0;j<X.length;j++)
  {
    System.out.println("J: "+j+":"+X[j]);
    for (i=0; i < 25; i++)
    {
      K1[i] = (float) (((C1[i] * (Math.pow(X[j], A1[i]))) + (D1[i] * tanh(X[i]/(Xk1[i] - 2))) - tanh(-2)) / (1 - tanh(-2)));`

      System.out.println("k1: "+i+":"+K1[i]);

      K2[i] = (float) (((C2[i] * (Math.pow(X[j], A2[i]))) + (D2[i] * tanh(X[i]/(Xk2[i] - 2))) - tanh(-2)) / (1 - tanh(-2)));

      System.out.println("k2: "+i+":"+K2[i]);
    }
  }

and output

J: 0:1
k1: 0:0.77030677
k2: 0:0.71177393
k1: 1:0.85542655
k2: 1:0.7439147
k1: 2:1.0791008
k2: 2:1.4420886
k1: 3:1.4016204
k2: 3:0.99215466
k1: 4:1.6363927
k2: 4:1.1519849
k1: 5:1.8587888
k2: 5:1.2869722
k1: 6:2.1131036
k2: 6:1.4581378
k1: 7:2.2821712
k2: 7:1.5228558
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

since the array X has less than 25 items, you are going to get exception after 8th iteration of inner loop. It seems like you should not use i variable to index X array. see this part:

tanh(X[i]/(Xk1[i] - 2)))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...