Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
public class CountCurrecy {
    /**
     * @param args
     */
    public static String[] numWords = { "One", "Two", "Three", "Four", "Five",
            "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve",
            "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen",
            "Eighteen", "Nineteen", "Ten", "Twenty", "Thirty", "Fourty",
            "Fifty", "Sixty", "Seventy", "Eighty", "Ninety", "Hundred",
            "thousand" };

    public static String file = "hkj ;ldsf akf; las dkf ;ldff thousand nine hundred twenty three k;sjdf, asldkfjs. lsakdfasdjf five hundred twenty three dksjlakfsd df sdaff. 89: eighty nine 8989: eight thousand nine hundred eighty nine.";

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        boolean isContinue = true;
        boolean isEnd = false;
        int count = 0;
        int startPos = 1;
        int endPos = 0;

        String fileWords[] = file.split(" ");
        String[] outputFile = fileWords.clone();
        for(int k=0; k<fileWords.length ; k++){
        outputFile[k] = fileWords[k];
        }

        for (int i=0; i< fileWords.length ; i++) {
            if (check(fileWords[i])) {
                if (isContinue) {
                    System.out.print("\n" + fileWords[i]);
                    startPos = i;
                    count++;
                    isContinue = false;
                } else {
                    endPos = i;
                    isEnd = true;
                    System.out.print(" " + fileWords[i]);
                }
            } else {
                if(isEnd){
                    for(int j = startPos ; j<=endPos ; j++){
                        outputFile[j] = "";
                        if(j==endPos)outputFile[j]="#";
                    }
                }
                isEnd = false;
                isContinue = true;
            }
            for(int j = startPos ; j<=endPos ; j++){
                outputFile[j] = "";
                if(j==endPos)outputFile[j]="#";
            }
        }
        System.out.println("\nCount" + count);
        System.out.println("\n\n\t\tOutput File\n");
        for(String word : fileWords)
            System.out.print(" "+word);
        System.out.println("\n\n\t\tOutput File\n");
        for(String word : outputFile)
            if(!word.equals(""))
                System.out.print(" "+word);
    }

    public static boolean check(String fileWord) {
        for (String numWord : numWords) {
            if(fileWord.charAt((fileWord.length() - 1)) == '.');
                if(numWord.equalsIgnoreCase(fileWord.substring(0, (fileWord.length() - 1))))
                    return true;
            else if (numWord.equalsIgnoreCase(fileWord))
                return true;
        }
        return false;
    }

}
Posted
Updated 19-Jan-14 20:45pm
v3
Comments
TorstenH. 20-Jan-14 2:45am    
I edited the format.

On second look I also added the tag 'homework'.
Please provide YOUR code and ask specific.

1 solution

You could find many online converters in web[^], check it out.

OR

Do Code Rewrite(From Scratch)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900