我正在创建一个java程序(通过cmd重定向)从具有如下格式的txtfile中读取标准输入:
0 Groningen Leek
1 Drenthe Emmen
2 Flevoland Almere
此索引一直持续到ID 518,然后每个ID都有两个坐标,如下所示:
0 6.665039 53.181004
0 6.66608 53.180733
0 6.666431 53.180642
0 6.666313 53.180329
1 6.814185 53.140736
1 6.813501 53.140584
1 6.811936 53.139683
(直到ID 518)
所以我想要的是一个带有两个参数(坐标)的cmd程序,然后程序通过查看索引来确定它来自哪个城镇和州。我怎样才能做到这一点? 我已经让程序读取每一行,并将ID和值存储在两个单独的数组中。
所以这就是我想要的程序:
% java LeesKaart 6.665039 53.181004 < GemeentesNL.txt
输出:
The coordinates x = 6.665039 and y = 53.181004 are located in: Town: Leek, State: Groningen.
到目前为止,这是我的代码:
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class LeesKaart {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
List<String> stringArray = new ArrayList<String>();
List<Integer> intArray = new ArrayList<Integer>();
while (StdIn.hasNextLine()) {
String line = StdIn.readLine();
String[] split = line.split(" ");
intArray.add(Integer.parseInt(split[0]));
stringArray.add(split[1]);
}
System.out.println(intArray);
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
System.out.println("The coordinates x =" + x + " and y =" + y + " are located in (town), (state)");
}
}