小编Zen*_*ser的帖子

Java输入来自终端的奇怪行为

我有以下代码,除了命令行参数,每次我写"Insertion"它不会进入if语句所以输出将是"Algorithm not found. Use: [ Insertion | Merge ]"

  public static void main(String[] args) throws IOException, InsertionAndMergeException, Exception {
    if( args.length < 2 ) {
      System.out.println("Use: <path> <algorithm> ");
      System.exit(1);
    }

    if(args[1] == "Insertion" || args[1] == "Merge"){

      testWithComparisonFunction(args[0], args[1], new RecordComparatorIntField());

    }else
      System.out.println("Algorithm not found. Use: [ Insertion | Merge ]");
  }  
Run Code Online (Sandbox Code Playgroud)

在命令行中我打字这个,我做错了什么?

java insertionandmergeusagejava/InsertionAndMer
geUsage "/home/zenoraiser/Scrivania/Università/Secondo Anno/Algoritmi/1718/LAB/Progetto/Integers.txt" "Insertion"
Run Code Online (Sandbox Code Playgroud)

java shell command-line args

1
推荐指数
1
解决办法
50
查看次数

Java Iterator.hasNext() 始终为 true

我已经检查过像这样的其他问题,但似乎我并不总是创建一个新的迭代器来检查始终相同的对象。

这是代码

        Iterator<Map.Entry<Node, Float>> it = graph.nodeNeighboursIterator(e); 
        System.out.println("extracted node "+ e.getLabel() + " number of neighbours "+ e.sizeNeighbours());
        while(it.hasNext()) {
            System.out.print(i + " " + e.getLabel() + " " + it +"-");
            i++;
        }
Run Code Online (Sandbox Code Playgroud)

该方法graph.nodeNeighboursIterator执行此操作

public Iterator<Map.Entry<Node, Float>> nodeNeighboursIterator(Node n) {
    return this.graph_weighted.get(n).entrySet().iterator();
}
Run Code Online (Sandbox Code Playgroud)

打印System.out.println("extracted node "+ e.getLabel() + " number of neighbours "+ e.sizeNeighbours());出正确数量的邻居,但循环仍然没有结束他的循环,你对此有何看法?

java iterator object hashmap infinite-loop

-2
推荐指数
1
解决办法
1212
查看次数

标签 统计

java ×2

args ×1

command-line ×1

hashmap ×1

infinite-loop ×1

iterator ×1

object ×1

shell ×1