0

We're asked to program pig Latin, all works fine except for the counting of occurrences of the string.

 public static void count(String [] wordperLine, String [] word){
         String check=" ";
         int count=1;
         for(int i=0; i<=wordperLine.length; i++){
              for(int x=0; x>word[i].length(); x++){
             for(int z=0; z<=word.length; z++){

             if(!word[x].equalsIgnoreCase(check))
             {
                 for(int y=0; y<=word[i].length(); y++){
                 if(word[x].equalsIgnoreCase(word[y]))
                 {
                    count++;
                    check=word[x];
                 }
                }
            }
            System.out.println(word[i]+"-"+count);
        }
    }
}
3
Contributors
2
Replies
11
Views
1 Year
Discussion Span
Last Post by JamesCherrill
0

Just one observation. Why is count initialized to 1 in line 3? I usually start at zero.

Added with edit. Same comment as JamesCherrill. No comments or design notes to decode what this function should do or how.

Edited by rproffitt: Add PS

1

I have absolutely no idea what that code is supposed to do, and I don't suppose many other people will either. Can you explain what it is supposed to do, maybe with a small example or two of correct input and output?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.