Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

requirements, requirements, requirements ;)


[Replies] [Reply] [View by Thread] [Help]
[Back To Programming]

Posted by Delta Cpt dopel On 2008-07-21 00:58:58
In Reply to RE: Programming challenge 3 in java. Posted by Alpha Tr chiken On 2008-07-21 00:54:35

Delta CptDelta Cpt
Delta Cpt dopel


Looking good, but missing a minor detail. The output should also be a file, not stdout.

On 2008-07-21 00:54:35, chiken wrote
>The "ignore formatting and punctucations" threw me off for a minute and required me to write an extra function , but all in all it was a good refresher.
>
>
>// code start
>import java.io.BufferedReader;
>import java.io.FileNotFoundException;
>import java.io.FileReader;
>import java.io.IOException;
>
>import java.lang.Character;
>public class p3 {
>
> /**
> * @param args
> * @throws IOException
> */
> public static void main(String[] args) throws IOException
> {
>
> String str;
> boolean b = false;
>
> BufferedReader in = new BufferedReader(new FileReader("somefile.txt"));
> while ((str = in.readLine()) != null)
> {
> b = isPalindrome(removeFormatting(str));
> if(b)
> {
> System.out.println(str);
> }
>
> }
>
> in.close();
>
> }
>
> public static String removeFormatting(String s)
> {
> String copy ="";
> for(int pos = 0; pos<=s.length()-1; pos++)
> {
> if(Character.isLetter(s.charAt(pos)))
> copy += s.charAt(pos);
> }
> return copy;
> }
>
> public static String reverseWord(String s)
> {
> String copyR = "";
>
> for(int pos = s.length()-1; pos>=0; pos--) {
> copyR += s.charAt(pos);
> }
> return copyR;
> }
>
> public static boolean isPalindrome(String s)
> {
> boolean b = false;
> int i = 0;
>
> String reversedWord;
> reversedWord= reverseWord(s);
> // System.out.println(reversedWord);
>
> if (s.equalsIgnoreCase(reversedWord))
> {
> b = true;
> }
> return b;
>
>
> }
>
>}
>
>// code end
>
>
>and the output matches your output.
>
>
>Next, i'll do it in scheme( for fun ) and *maybe* prolog.
>
>


Replies:


Guest:
Subject:
Message:
Signature:
Optional Image Link:
http://

CyberArmy::Forum v0.6
Generated In 0.02302 seconds


About Us | Privacy Policy | Mission Statement | Help