jeudi 29 octobre 2015

readfile count increase issue

my code:

  while (stream.hasNext()) {
        name = stream.next();

        if (name.equals(nextName)) {
            for (int i = 1; i < 4; i++) {
                if (i == 3) {
                    cat3++;
                }
                    totalContracts++;
                    if (name.charAt(0) == 2 || name.charAt(0) == 3) {
                        break;
                    }
                }
            }
        }

it is reading a file like this:

1
name1
name2
name1
name3
2
name2
name1
name1
name2
3
name3
name3

I am trying to keep a total of how many times each name is listed under each number, but instead it is racking up the names in the whole file under each number, and counting the total number of names 3 times for the total...?

Aucun commentaire:

Enregistrer un commentaire