Share Pastebin
Guest
Public paste!

String Comparison

By: a guest | Sep 2nd, 2010 | Syntax: Java | Size: 1.55 KB | Hits: 59 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. public class Driver
  2. {
  3.         public static void main(String args[])
  4.         {
  5.                 String nounString="cat dog fish bug car Iceguize Vendetta pixel Nob cow crow crap crunk crotch ravine niggers pixels dogs asian cows sheep crevasse wool water bomb blimp graphics";
  6.                 String[] nounArray = nounString.split(" ");
  7.                 String sentenceString="The quick brown cat jumped over the lazy dog";
  8.                 String[] sentenceNouns=getCommon(nounString,sentenceString);
  9.                
  10.                 for (int i=0 ; i<sentenceNouns.length ; i++)
  11.                 {
  12.                         System.out.println(sentenceNouns[i]);
  13.                 }
  14.  
  15.                 String sentenceFinal=nounReplace(sentenceString,sentenceNouns);
  16.         }
  17.        
  18.         public static String[] getCommon(String A, String B)// Defind the nouns in an array
  19.         {
  20.                 String[] splitA = A.split(" ");                                 //
  21.                 String[] splitB = B.split(" ");                                 //
  22.                
  23.                 String Matches = "";                                                    //
  24.                
  25.                 for(int i=0;i<splitA.length;i++)                                //
  26.                 {
  27.                         for(int j=0;j<splitB.length;j++)                        //
  28.                         {
  29.                                 if(splitA[i].equals(splitB[j]))                 //
  30.                                 {
  31.                                         Matches += splitA[i] + " ";                     //
  32.                                 }
  33.                         }
  34.                        
  35.                 }
  36.                 return Matches.split(" ");                                              //
  37.         }      
  38.         public static String nounReplace(String sentenceString,String[] nounMatch) // Replace nouns
  39.         {
  40.                 String sentenceEnd = "";
  41.                 for(int i=0;i<nounMatch.length;i++)
  42.                 {
  43.                         String[] sentenceArray = sentenceString.split(nounMatch[i]);
  44.                         if(sentenceArray.length > 2)
  45.                         {
  46.                                 for(int j=0;j<sentenceArray-1.length;j++)
  47.                                 {
  48.                                         senentceEnd += sentenceArray[j+1];
  49.                                 }
  50.                         }
  51.                         else
  52.                         {
  53.                                 senentceEnd = sentenceArray[1];
  54.                         }
  55.                 }
  56.                 return sentenceArray(0) + "Noun" + sentenceEnd;
  57.         }
  58.  
  59. }