java如何将此坐标图拆分为除第一个数字外的其他数字,并将(x,y)存储为二维数组
as the title,i want to split the coordinate chart as following
拆分后,应该是88 72 47 40 13 67.... 并将x和y值存储到数组中 如何修改。拆分(“”),如果使用
.split(""tab"")
它完全拆分字符串,而不忽略第一个数字 ,以及如何将这些数字存储到二维数组中
package coordinates;
import java.util.*;
import java.io.*; //scanner and reader
public class Path {
public static void readfromtxt() throws Exception{
FileReader File = new FileReader("coordinations.txt");
BufferedReader Reader= new BufferedReader(File);
String text="";
String textsub="";//to isolate first line
String line=Reader.readLine();
textsub=text+line+"\n";
while(line!=null){//if there are lines
text=text+line+"\n";//pass data of line into text
line=Reader.readLine();//load data of line
String[]textArrays=line.split(" ");//split by tab 1.1 2.88 3.72
for(String textArray:textArrays){
int coordinates=Integer.parseInt(textArray);// to int
System.out.println(coordinates);}}
# 1 楼答案
将最后一位从
到
# 2 楼答案
以下是一个可运行的工作解决方案(注释解释了某些部分):
这将删除顶行,忽略第一列,并提供二维数组(
array
)。 注意:使用throws Exception
通常是不好的,因为这可能会阻止您捕获并注意到代码中的特定问题。这个程序唯一需要抛出的异常是IOException
我还更改了一些方法和变量名,以适应Java的编码标准