Optional: As an extra challenge, have your program reject only lines that contain a profane word exactly. For example, Dogmatic concatenation is a small category. This sentence should not be considered profane.
import java.util.Scanner;
public class CS1_Javed_X7_1
{
public static void main(String[] args)
{
String a;
int case_num = 0;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a sentence:");
a = keyboard.nextLine();
a = a.toLowerCase();
if (a.indexOf("cat") != -1) //this section detects for the profane words
case_num = 1;
else if (a.indexOf("dog") != -1)
case_num = 1;
else if (a.indexOf("llama") != -1)
case_num = 1;
switch(case_num) //This secton gets the correct message to print.
{
case 1:
System.out.println("your sentence consists of profanity");
break;
default:
System.out.println("No profanity detected in the Sentence");
}
}
}
Question: How do i make My code so its not doing the optional part?.. What method should i use besides .indexOf to get the problem. I am asking this because my professor wants the code without the optional part. I could not figure out another way to do the program without using indexOf. I tried using .equalsIgnoreCase() but that would not help me because that compares the entire string and does not look for a sub-string.
This post has been edited by AhmerjavedC++: 20 March 2011 - 05:05 PM

New Topic/Question
Reply




MultiQuote







|