-3

I am looking to write a method without using enhanced loops, but am not sure how to convert them exactly. The method is:

public static int charFrequency (String[]s, char c){

    int freq = 0;
    for(String s2 : s) {
        char[] newArray = createChars(s2);
        for (char c2: newArray)
            if(c2 == c) freq++;
    }
}
5
  • 1
    What have you tried? What problems you are facing? Also why would you want to reduce readability of your code? Commented Mar 28, 2016 at 17:40
  • Is there a particular reason you want to do this? The newer style of loop is there precisely so that you don't have to use the old-style loop. Commented Mar 28, 2016 at 17:42
  • The for Statement Commented Mar 28, 2016 at 17:43
  • Really I'm just looking for an example of what a for loop would look like if it was derived from an enhanced for loop. Commented Mar 28, 2016 at 17:45
  • @templatetypedef for no other reason than learning both. I taught myself a bit of java and am trying to learn all the different kinds of loops. I'm trying to figure out how the enhanced loop is created from a regular for loop by working backwards Commented Mar 28, 2016 at 17:46

1 Answer 1

0

Here you go:

for(int index = 0 ; index < s.length ; index++){
    //Logic
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.