스캐너를 통해 입력 된 수의 문자열 (int T
)을 입력 받아 arraylist에 저장하는 프로그램을 작성하고 싶습니다. 그런 다음 입력을 검사하여 일치하는지 또는 다른 배열의 문자가 포함되어 있는지 확인하려고합니다.Arraylist.contains 수표 문자열이 없습니다.
예 입력 :
1 ABCD
예 출력 :
이Good
문제 : 나는 "좋은"또는 "나쁜"출력을 얻을하지 않는 코드를 실행하면, 대신 내가 오류 디버그 콘솔이 시작됩니다.
정확한 오류 :
Scanner.throwFor() line: not available. Source not found
import java.io.*;
import java.util.*;
public class RNA {
public static void main(String[] args) {
String X [] = {"A", "B", "C", "D"}; // Array to be checked against
List<String>A = new ArrayList(); // ArrayList to be imported
Scanner q = new Scanner(System.in);
System.out.println("How Many Sets of Strings do you want?");
int T = q.nextInt(); // number of Strings to be imported
q.nextInt(); // allows to reset Scanner
for(int i = 0 ; i < T; i ++){
A.add(q.nextLine()); //imports stuff to add to array A
}
Iterator<String> ListChecker = A.iterator();
while((ListChecker.hasNext())) { //continues as long as DNA Check has an index to go to
if (A.contains(X)) { //Checks A for X
System.out.println("Good"); //Prints out good if the check is good
}
else {
System.out.println("Bad"); //Prints out bad if the check is bad
}
}
}
}
오류가 발생한 행이 있습니까? –
어디에서 발생했는지 보여줄 수 있습니까? – Marv
문자열 개체를 확인하고있을 수 있습니까? 왜냐하면 문자열 객체는 값이 같을 수 있지만 참조가 아니라는 점에서 다소 까다 롭습니다. – JClassic