gpt4 book ai didi

java - 如何并行输出行号?

转载 作者:行者123 更新时间:2023-12-01 07:34:45 25 4
gpt4 key购买 nike

下面是我的代码,它将从 URL 读取行并将其输出。我想知道如何才能输出行号,例如excel中的行号。

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Scanner;


public class helloworld {

public static void main(String[] args) throws IOException {
URL yahh = new URL("https://docs.google.com/spreadsheet/pub?key=0AqSBI1OogE84dDJyN0tyNHJENkNyYUgyczVLX0RMY3c&single=true&gid=0&range=A2%3AA200&output=txt");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahh.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)

System.out.println(inputLine);

in.close();

}
}

当前输出是:

11111
22222
33333
44444
55555
66666
77777
88888
99999
100000

我希望它是

1   11111
2 22222
3 33333
4 44444
5 55555
6 66666
7 77777
8 88888
9 99999
10 100000

最佳答案

声明一个行号变量并在每次迭代时在循环中递增它:

 int line=0;
while((inputLine = in.readLine()) != null){
line++;
System.out.println(line + "\t" + inputLine);
}

关于java - 如何并行输出行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13593764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com