for循环迭代无法找到让我跳跃值的东西

时间:2017-11-20 04:34:13

标签: java

正在阅读的文件

Rob Gronkowski 48
Zach Ertz 34
Travis Kelce 29
Evan Engram 15
Jimmy Graham 12
Cameron Brate 10
Delanie Walker 9
Kyle Rudolph 6
Austin Seferian-Jenkins	6
Jack Doyle 6
Hunter Henry 5
Jason Witten 4
Jordan Reed 4
Vernon Davis 3
Jared Cook 3
Tyler Kroft 3
Ed Dickson	3
Charles Clay	3
George Kittle	3
Antonio Brown	67
DeAndre Hopkins	62
A.J. Green	62
Mike Evans	62
Julio Jones	56
Michael Thomas	55
Dez Bryant	53
Michael Crabtree 45
Brandin Cooks	42
Tyreek Hill	42
Doug Baldwin	42
Keenan Allen	32
Jarvis Landry	29
Will Fuller	29
Amari Cooper	29
Stefon Diggs	29
Alshon Jeffery	27
Nelson Agholor	24
Adam Thielen	24
Chris Hogan	24
Golden Tate	24
Demaryius Thomas 22
Jordy Nelson 22
Larry Fitzgerald 22
DeSean Jackson	21
JuJu Smith-Schuster 19
Devante Parker	18
Devin Funchess	18
Kelvin Benjamin	18
T.Y. Hilton	17
Emmanuel Sanders 17
Marvin Jones	15
Rishard Matthews 14
Pierre Garcon	14
Cooper Kupp	14
Sterling Shepard 14
Paul Richardson	11
Danny Amendola	10Le’Veon Bell 70
Kareem Hunt	63
Todd Gurley	63
Leonard Fournette 60
Melvin Gordon	60
LeSean McCoy	60
Mark Ingram	50
Devonta Freeman	50
Jordan Howard	50
Lamar Miller	41
Doug Martin	34
Carlos Hyde	34
Aaron Jones	27
Alvin Kamara	27
Jerick McKinnon	24
DeMarco Murray	21
Chris Thompson	21
Jay Ajayi	21
Joe Mixon	18
C.J. Anderson	17
Tevin Coleman	17	
Christian McCaffrey 17
Derrick Henry	16 
Alex Collins	16
Dion Lewis	15
Adrian Peterson	13
Duke Johnson	12
Marshawn Lynch	11
Ameer Abdullah	10
Bilal Powell	9
LeGarrette Blount 9
Marlon Mack	9
James White	8
Ezekiel Elliott	7
Latavius Murray	7
Frank Gore	7
Isaiah Crowell	7
Orleans Darkwa	7
Kenyan Drake	5
Matt Forte	5
Darren McFadden	5
Alfred Morris	5
Damien Williams	3
Tarik Cohen	3
Jonathan Stewart 3
Robert Kelley	3
Danny Woodhead	3
Ty Montgomery	2
Javorius Allen	2
Mike Gillislee	2
Thomas Rawls	2
Theo Riddick	2
DeAndre Washington 2
Eddie Lacy 2
Giovani Bernard 2
Andre Ellington 2
Austin Ekeler 2
Jalen Richard 2
Ted Ginn 10
Robby Anderson 10
Jermaine Kearse	9
Davante Adams 9
Kenny Stills 9
Sammy Watkins 9
Marqise Lee 5
Mohamed Sanu 5
Allen Hurns 5
Josh Doctson 5
Jamison Crowder 4
Jeremy Maclin 3
Randall Cobb 3
Tyrell Williams	3
Robert Woods 3
Corey Davis 3
Jordan Matthews 3
Tyler Lockett 3
John Brown 2
Willie Snead 2
Donte Moncrief 2
Deshaun Watson 31
Dak Prescott 26
Tom Brady 24
Russell Wilson 22
Drew Brees 22
Carson Wentz 20
Alex Smith 14
Kirk Cousins 13
Matthew Stafford 11
Marcus Mariota 11
Tyrod Taylor 11
Cam Newton 11
Matt Ryan 11
Philip Rivers 8

有些问题一直在寻找答案。我发现我的for循环迭代不正确它打印系列:0,1,2,10等我想知道是否有人可以指出我的缺陷,所以我可以解决这个问题。我很欣赏任何读这篇文章的人,以及代码长度的appolgozie。但只想包括一切,所以我不会错过任何东西。 FOR LOOP LINE 87 再次感谢,真诚的java noob

CODE

package trades;

import java.io.BufferedReader;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.*;

public class Fantasy {

    public static void main(String[] args) {
        int[] playerRanking = new int[75];   
        String infoComingIn = null;
        //Finding file path
        String filename = "C:\\Users\\Karanvir\\Desktop\\21days\\players.txt";
        File filez = new File(filename);

        BufferedReader br;    
        String[] playerNames = new String[75];    
        int counterOfReadLines = 0;
        Pattern p = Pattern.compile("[0-9]{2,3}");

        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        try {
            br = new BufferedReader(new FileReader(filez));    
            playerNames[counterOfReadLines] = br.readLine();

            while (br.readLine() != null) {
                counterOfReadLines = counterOfReadLines + 1;
                playerNames[counterOfReadLines] = br.readLine();
                System.out.println(playerNames[counterOfReadLines - 1]);
            }
            br.close(); 

            for (int i = 0; i < playerNames.length; i++) {
                Matcher m = p.matcher(playerNames[i]);

                if (m.find()) {
                    String matched = m.group(0);
                    int addToArray = Integer.parseInt(matched);
                    playerRanking[i] = addToArray;
                    System.out.println(i);
                }
            }
        } catch (Exception e) {}
    }
}

1 个答案:

答案 0 :(得分:0)

好的,通过看帖子,我只能指出一个问题。因为你在行

之前递增counterOfReadLines变量

playerNames [counterOfReadLines] = br.readLine();

所以会发生什么是playerNames正在初始化索引1的数组而不是0,当你试图调用下面的循环: -  for(int i = 0; i&lt; playerNames.length; i ++){                 Matcher m = p.matcher(playerNames [i]);

csrftoken_cookie = [cookie for cookie in cookie_jar if cookie.name == 'csrf_token'][0]

它以0递增。因此要么从i = 1开始,要么在行后增加counterOfReadLines playerNames [counterOfReadLines] = br.readLine();

所以你的错误会消失......!如果没有让我知道...... :)!