0 Members and 3 Guests are viewing this topic.
import java.util.*;import java.lang.*;public class Prog508a{ public static Scanner k=new Scanner(System.in); public static int yesorno=1; public static String YN=""; public static int yncheck(String YesOrNo) { if(YN.equals("Yes")) yesorno=1; else if(YN.equals("No")) yesorno=0; else if( !(YN.equals("Yes") || YN.equals("No")) && (YN.equalsIgnoreCase("yes") || YN.equalsIgnoreCase("no"))) { System.out.print("Capitalization is important Yes or No? "); YN=k.nextLine(); yncheck(YN); } else {System.out.print("You must answer either Yes or No? "); YN=k.nextLine(); yncheck(YN); } return yesorno; } public static void main(String args[]) { String str="",str2="",str3=""; while(yesorno==1){ System.out.println(); System.out.print("Enter a sentence: "); str=k.nextLine(); String[] sarray = str.split(" "); int len = sarray.length; for(int i=0;i<len;i++) { char[] word = sarray[i].toCharArray(); char firstletter = word[0]; int len3=word.length; int len4=len3-1; if(firstletter!='a' && firstletter!='e' && firstletter!='i' && firstletter!='o' && firstletter!='u' && firstletter!='A' && firstletter!='E' && firstletter!='I' && firstletter!='O' && firstletter!='U') { for(int j=0;j<=len4-1;j++) { word[j]=word[j+1]; } word[len3-1]=firstletter; } for(int l=0;l<=len3-1;l++) { str2=str2+word[l]; } str3=str3+str2+" "; str2=""; } str3=str3.replace(" ","ay "); System.out.println(str3); str3=""; System.out.print("Do you wish to convert another sentence? (Yes/No) "); YN=k.nextLine(); yncheck(YN); } }} */
import java.util.*;public class Censor{ public static void main(String[] args){ Scanner reader = new Scanner(System.in); System.out.print("Enter a string to censor: "); String evilness = reader.nextLine(); System.out.println("Your string in a more holy format: \n" + censor(evilness)); System.out.print("\nAgain? (y/n) "); if(reader.nextLine().equalsIgnoreCase("y")) main(null); //recursive calls to main? i think yes. } public static String censor(String evilness){ String[] badWords = {"fuck","shit","damn","ass","FUCK","SHIT","DAMN","ASS"}; //yes, i know there are more swear words. this covers the basics. String[] replacementWords = {"apple","magical","unicorn","fairies","endear","renowned","butterflies","sugar"}; Random r = new Random(); for(int i = 0; i < badWords.length; i++){ int indexOfBadWord = evilness.indexOf(badWords[i]); if(indexOfBadWord != -1){ String begin = evilness.substring(0,indexOfBadWord); String replacement = replacementWords[r.nextInt(replacementWords.length)]; String end = evilness.substring(indexOfBadWord + badWords[i].length()); evilness = begin + replacement + end; i = -1; } } return evilness; //now holy. }}
Lol, "apple this magical unicorn". Interesting program, nemo. I love the comment on that return statement.EDIT: What would be really funny, is to analyze the sentence, and get a new version that was "prettier" so that everyone talked pretty.So "Hey, I think your program is a fail" becomes "I think your program is missing some butterflies, but other than that, I think the unicorns were happy."
Quote from: graphmastur on December 09, 2010, 10:24:57 pmLol, "apple this magical unicorn". Interesting program, nemo. I love the comment on that return statement.EDIT: What would be really funny, is to analyze the sentence, and get a new version that was "prettier" so that everyone talked pretty.So "Hey, I think your program is a fail" becomes "I think your program is missing some butterflies, but other than that, I think the unicorns were happy."i think that's a little beyond my word processing abilities. it'd be cool if i made an advanced library to process strings, though.also, if you want, you can just copy/paste my source code and add words. if you want to add the swear words list to include "snow" for some reason, you can do that. you can also add replacement words, if you wanted to replace snow with honey. maybe i could make a function that, when a certain word is spotted, it will always replace it with a certain other word...
interesting. you know what i just thought of doing? censoring a string to take out all the swear wordsedit: just finished it. it will change something like this:Spoiler For language: You fucking ass.intoYou endearing unicorn.Code: [Select]import java.util.*;public class Censor{ public static void main(String[] args){ Scanner reader = new Scanner(System.in); System.out.print("Enter a string to censor: "); String evilness = reader.nextLine(); System.out.println("Your string in a more holy format: \n" + censor(evilness)); System.out.print("\nAgain? (y/n) "); if(reader.nextLine().equalsIgnoreCase("y")) main(null); //recursive calls to main? i think yes. } public static String censor(String evilness){ String[] badWords = {"fuck","shit","damn","ass","FUCK","SHIT","DAMN","ASS"}; //yes, i know there are more swear words. this covers the basics. String[] replacementWords = {"apple","magical","unicorn","fairies","endear","renowned","butterflies","sugar"}; Random r = new Random(); for(int i = 0; i < badWords.length; i++){ int indexOfBadWord = evilness.indexOf(badWords[i]); if(indexOfBadWord != -1){ String begin = evilness.substring(0,indexOfBadWord); String replacement = replacementWords[r.nextInt(replacementWords.length)]; String end = evilness.substring(indexOfBadWord + badWords[i].length()); evilness = begin + replacement + end; i = -1; } } return evilness; //now holy. }}
interesting. you know what i just thought of doing? censoring a string to take out all the swear wordsedit: just finished it. it will change something like this:Spoiler For language: You fucking ass.intoYou endearing unicorn.
Not public commands, though. Earlier I had to mute the IRC channel (disable it completely) to stop a spam fest because no one would listen. Imagine with bot commands, now. X.x