要产生[20,999]之间的随机整数使用哪个表达式?
A. (int)(20+Math.random()*979)
B. 20+(int)(Math.random()*980)
C. (int)Math.random()*999
D. 20+(int)Math.random()*980
查看答案
set集合如何处理重复元素
A. 如果加入一个重复元素将抛出异常
B. 如果加入一个重复元素add方法将返回false
C. 集合通过调用equals方法可以返回包含重复值的元素。
D. 重复值将导致编译出错。
在Applet画面的左上角至右下角画一条直线,则//draw处应如何选择?import java.awt.*;import java.applet.*;public class myApplet extends Applet {public void paint(Graphics g) {//draw}}
A. g.drawLine(0,0,getHeight(),getWidth());
B. g.drawLine(0,getWidth(),0,getHeight());
C. g.drawLine(0,getWidth(),getHeight(),0);
D. g.drawLine(getWidth(),getHeight(),0,0);
在同一目录编译和运行以下两文件结果如何?
//文件 P1.java
package MyPackage;
class P1{
void afancymethod(){
System.out.println("What a fancy method");
}
}
//文件 P2.java
public class P2 extends P1{
public static void main(String argv[]){
P2 p2 = new P2();
p2.afancymethod();
}
}
A. 两个均通过编译,P2运行时输出 What a fancy method
B. 没一个通过编译
C. 两个均通过编译,但P2运行时出错
D. P1 通过编译,但P2出现编译错误
下列程序运行的结果为:public class test {public static void main(String args[]) {int i;float f = 2.3f;double d = 2.7;i = ((int)Math.ceil(f)) * ((int)Math.round(d));System.out.println(i);}}
A. 4
B. 5
C. 6
D. 6.1
E. 9