小编bit*_*tli的帖子

如何使用"x <= y && x> = y && x!= y"使循环无限?

几年前我有这个面试问题,但我还没有找到答案.

什么应该是x和y来进行无限循环?

while (x <= y&& x >= y && x != y) {

}
Run Code Online (Sandbox Code Playgroud)

我们试着用Nan,infinity+/-,null

floatVS int.

java

23
推荐指数
2
解决办法
883
查看次数

如何让我的scala功能更快?

isSortedScalaJava中都有功能.当我测量两个函数的执行时间时,我发现Scala版本非常慢.它运行大约3.2秒为10000 Int但Java版本只运行大约10ms!如何让我的scala版本更快?

这些是实施:

斯卡拉:

def main(args: Array[String]) ={
    println(isSorted(getArray, (x:Int,y:Int) => x<y ))
}
def isSorted[A](items : Array[A], cond: (A,A) => Boolean) : Boolean = items match{
  case Array(_) => true 
  case Array(x,y) =>cond(x,y)
  case Array(_*) => cond(items(0),items(1)) && isSorted(items tail,cond)
}
Run Code Online (Sandbox Code Playgroud)

Java的:

public static void main(String... args){
    Sorter<Integer> sorter=new Sorter<Integer>();
    System.out.println(sorter.isSorted(sorter.getList(),new Comparator<Integer>() {
        @Override
        public int compare(Integer o1, Integer o2) {
            return o2.compareTo(o1);
        }
    }));
}
public …
Run Code Online (Sandbox Code Playgroud)

java scala

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

标签 统计

java ×2

scala ×1