코드를 실행 한 후에 왜 scoreMatrix
배열이 항상 전체 배열에 마지막 할당을하는지 모르겠습니다. 여기 개체의 배열에 값을 올바르게 할당하는 방법은 무엇입니까?
String input, seq="ACGT";
PairScore[] scoreMatrix = new PairScore[16];
for(int x = 0; x<16 ; x++){
scoreMatrix[x] = new PairScore();
}
Scanner user_input = new Scanner(System.in);
for(int i = 0; i <4;i++){
input=user_input.nextLine();
String[] inputSplite = input.split("\\s+");
for(int j=0; j<4;j++){
scoreTable[i][j] = Integer.parseInt(inputSplite[j]);
}
}
for(int x = 0; x<4 ; x++){
for(int y=0; y<4; y++){
scoreMatrix[x*4 +y].fString = Character.toString(seq.charAt(x));
scoreMatrix[x*4 +y].sString = Character.toString(seq.charAt(y));
scoreMatrix[x*4 +y].score = scoreTable[x][y];
}
}// Fix the score pair problems;
for(int x1 = 0; x1<4 ; x1++){
for(int y1=0; y1<4; y1++){
System.out.println(scoreMatrix[x1*4 +y1].fString+scoreMatrix[x1*4 +y1].sString+scoreMatrix[x1*4 +y1].score);
}
}
는 클래스 PairScore
public class PairScore {
public static String fString;
public static String sString;
public static int score;
} 코드입니다
언제 입력
나는 다음과 같은 결과를 얻었다1 -1 -1 -1
-1 1 -1 -1
-1 -1 1 -1
-1 -1 -1 1
:
TT1TT1TT1TT1.....TT1
을
AA1AC-1AG-1AT-1CA-1CC1...TT1
왜 값 TT1을하고 배열의 나머지 부분에 할당 않습니다 :
는하지만 코드에서 아래 결과를 얻을 것으로 기대?
'score'는 정적입니다. 이것은 어디서나 수정되는 방식에 영향을줍니다. – ha9u63ar