面试题:以下程序的输出结果是什么?
2015-02-25 09:42
267 查看
package com.njue.mis;
import java.util.*;
public class Test {
public static void main(String[] args){
Queue<Integer> queue = new PriorityQueue<Integer>(10,
new Comparator<Integer>(){
public int compare(Integer i,Integer j){
int result = i%2-j%2;
if(result == 0)
result = i -j;
return result;
}
});
for(int i = 0; i<10; i++)
{
queue.offer(i);
}
for(int i = 0; i<10; i++)
{
System.out.println(queue.poll());
}
}
}
import java.util.*;
public class Test {
public static void main(String[] args){
Queue<Integer> queue = new PriorityQueue<Integer>(10,
new Comparator<Integer>(){
public int compare(Integer i,Integer j){
int result = i%2-j%2;
if(result == 0)
result = i -j;
return result;
}
});
for(int i = 0; i<10; i++)
{
queue.offer(i);
}
for(int i = 0; i<10; i++)
{
System.out.println(queue.poll());
}
}
}
相关文章推荐
- java集合类面试题以下程序的输出结果是什么
- 面试题 以下程序的输出结果是什么
- 字符串面试题:以下程序的输出结果是
- 面试题:以下程序的输出结果是
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。例如:1 + 2 + 34 – 5 + 67 – 8 + 9 = 100。
- 以下代码的输出结果是什么?
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。
- 文章标题编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。
- 今天的面试题:填写程序输出结果
- (面试题)输出下列程序结果(考察字符串与其他类型+连接)
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。例如:1 + 2 + 34–5 + 67–8 + 9 = 100。
- 以下程序输出结果是____。
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是 100 的程序,并输出所有的可能性。 例如:1 + 2 + 34 – 5 + 67 – 8 + 9 = 100
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。例如:1 + 2 + 34 – 5 + 67 – 8 + 9 = 100。
- 以下C#程序的输出结果是( )。
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。
- 【华为机试题】请在123456789之间添加+号或者-号,也可以什么都不填,使得等式的运算结果等于a。要求程序输出等式成立的个数b。测试用例:a=5时,b=21。
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是 100 的程序,并输出所有的可能性
- 以下代码的输出结果是什么?