고양이, 개, 라마라는 세 단어를 걸러 내야합니다. 프로그램은 cAt와 같은 경우에이 단어를 걸러 내야합니다.모욕적 필터 - Java
import java.util.Scanner;
public class Assign5 {
public static void main(String[] args)
{
String cat,dog,llama,x,y,z;
System.out.println("Enter a word");
Scanner keyboard = new Scanner (System.in);
x=keyboard.next();
y=x.toLowerCase();
if (y.indexOf("cat")!=-1||y.indexOf("dog")!=-1|y.indexOf("llama")!=-1)
{
System.out.println("Profanity Detected");
}
else if(y.indexOf("cat")!=-1||y.indexOf("dog")!=-1|y.indexOf("llama")!=-1)
{
y.charAt(0);
y.charAt(1);
y.charAt(2);
y.charAt(3);
System.out.println("No Profanity Detected");
}
}
}
는 출력 :
단어를 입력독단적
욕설 내가 그 세 단어가 포함 된 단어를 걸러하려고
을 감지. 그것은 그것을 읽고 있지 않습니다. charAt를 사용하여 문자 분할을 시도했지만 작동하지 않습니다. if를 계속 읽습니다. 또한 어떻게 대소 문자를 구분합니까? "cAt"를 모독으로 감지하지만 "고양이"도 모독으로 간주합니다. 나는 사용할 수 없다 : 배열, for, while 또는 split. 지금은 if-else, switch 및 charAt로만 작업 할 수 있습니다.
@ The Scrum Meister : 나는 또한 하나를 올렸습니다. 이 문제를 해결하는 데 여전히 문제가있어 재 게시합니다.
String.contains() http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#contains%28java.lang.CharSequence%29 – Nishant
Clbuttic !!! !!! – Daniel
이 프로젝트를 계속하기 전에이 기사를 읽어보십시오. http://www.telegraph.co.uk/news/newstopics/howaboutthat/2667634/The-Clbuttic-Mistake-When-obscenity-filters-go-wrong.html. 사실, 그냥 구글 "clbuttic" – JohnFx