小编0li*_*sa0的帖子

读取多行中的多个整数

我目前正在用图论编写我的学士论文,并使用java扫描器将带边的txt文件转换为我的Java类图.我的txt文件如下所示:

1 2 72 3
2 3 15 98
4 7 66 49
5 6 39 48
6 9 87 97
8 13 31 5

整数排序为:源顶点,汇点顶点,成本,容量.

我的代码如下:

Graph graph = new Graph(false);
File f = new File("Filepath");
Scanner in = new Scanner(f);
while (in.hasNextLine())
{
    for (int i =1; i<= numberEdges; i++)
    {
        String s = in.nextLine();
        try (Scanner inscan = new Scanner(s)) {
            while (inscan.hasNext())
            {
                int source = inscan.nextInt();
                int sink = inscan.nextInt();
                double cost =inscan.nextDouble();
                double capacity …
Run Code Online (Sandbox Code Playgroud)

java java.util.scanner

5
推荐指数
2
解决办法
1595
查看次数

标签 统计

java ×1

java.util.scanner ×1