[java]
import java.util.ArrayList;
public class Excercise_049 {
public static void main(String[] args) {
ArrayList<String> identifierList = new ArrayList<>();
identifierList.add("for");
identifierList.add("Class");
identifierList.add("i");
identifierList.add("num");
identifierList.add("public");
identifierList.add("a");
ArrayList<String> excludeList = new ArrayList<>();
excludeList.add("class");
excludeList.add("for");
excludeList.add("if");
excludeList.add("public");
excludeList.add("static");
excludeList.add("while");
ArrayList<String> valid = new ArrayList<>();
ArrayList<String> invalid = new ArrayList<>();
for(String word : identifierList) {
boolean isValid = true;
for(String ex : excludeList) {
if(word.equals(ex)) {
invalid.add(word);
isValid = false;
break;
}
}
if(isValid) {
valid.add(word);
}
}
System.out.println("有効 : " + valid);
System.out.println("無効 : " + invalid);
}
}
[/java]