-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++;
    }
}
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
  • 1
    What have you tried? What problems you are facing? Also why would you want to reduce readability of your code? – Pshemo Mar 28 '16 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. – templatetypedef Mar 28 '16 at 17:42
  • [The for Statement](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html) – dsh Mar 28 '16 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. – Jack Butler Mar 28 '16 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 – Jack Butler Mar 28 '16 at 17:46

1 Answers1

0

Here you go:

for(int index = 0 ; index < s.length ; index++){
    //Logic
}
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102