第1题:
A.publicinthashCode(){return343;}
B.publicinthashCode(){returnsize.hashCode();}
C.publicinthashCode(){returncolor.hashCode();}
D.publicinthashCode(){return(int)(Math.random()*1000);
第2题:
下面程序段的输出结果是 public class Test{ public static void main(Stringargs[]){ int x,y; x=(int)Math.sqrt(5)/2+(int)Math.random()*5/2; y=(int)Math.sqrt(3)/2+(ht)Math.random()*3/2; if(x>y) System.out.println(”x>y”); else if(x=y) System.out.println(”x=y”); else System.out.Println(”x<y”); } }
A.x>y
B.x=y
C.x<y
D.编译错误
第3题:
在程序中,DataPool是一个数据池,能存放一个血型数据,线程a和线程b负责向其中存放数据,一次只能有一个线程向其中存放数据,数据放入DataPool以后,该线程随机休眠一段时间,让另外一个线程运行,请将程序补充完整。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
class PutData extends Thread
{
DataPool s;
int c;
String name;
public PutData(DataPool s,String name)
{
this.s=s;
this.name=name;
}
public void run()
{
for(int i=0;i<10000000;i++)
{
c=(int)(Math.random()*10);
s.setData(c);
System.out.println(name+":push"+c);
try
{
______((int) (Math.random()*1000));//休眠
}
catch(InterruptedException e)
{}
}
}
}
class DataPool
{
private int data=0;
public ______void setData(int d)
{
data=d;
}
}
public class simple
{
public static void main(String[] args)
{
DataPool s=new DataPool();
PutData a=new PutData(s,"Thread a");
PutData b=new PutData(s,"Thread b");
a.start();
b.start();
}
}
第4题:
下面程序段的输出结果是______。 public class Test{ public static void main(String args[ ]){ int x,y; x=(int)Math.sqrt(5/2)+(int)Math.random( )*5/2; y=(int)Math.sqrt(3/2)+(int)Math.random( )*3/2; if(x>y) System.out.println("x>y"); else if(x==y) System.out.println("x=y"); else System.out.println("x<y"); } }
A.x>y
B.x=y
C.x<y
D.编译错误
第5题:
A.(int)(20+Math.random()*979)
B. 20+(int)(Math.random()*980)
C. (int)Math.random()*999
D. 20+(int)Math.random()*980
第6题:
动作语句:math.random()*10表示产生0--10之间的随机数。
A对
B错
第7题:
在Math类中random方法可以产生随机数。如果从1到100之间产生一个随机整数(大于等于1,小于等于100),并赋值给n,那么下面语句正确的是()。
第8题:
棘轮机构除常用来实现间歇运动的功能外,还常用来实现什么功能?
第9题:
class Sock { String size; String color; public boolean equals(Object o) { Sock s = (Sock) o; return color.equals(s.color); } // insert code here } 哪两个满足 hashCode 的约定?()
第10题:
第11题:
(int)(20+Math.random()*97)
20+(int)(Math.random()*980)
(int)Math.random()*999
20+(int)Math.random()*980
第12题:
(难度:中等)Math.random()返回 0(不包括) 至 1(不包括) 之间的随机数
答案:(no)
第13题:
执行int x=(int)(Math.random()*100);语句时,不会出现下列哪个数值?
A.1
B.35
C.48
D.100
第14题:
下列声明语句中没有起到定义作用的是( )。
A.int count;
B.const double pi=3.14159;
C.extern long index;
D.int max(int a,int b){return a>b? a:b;}
第15题:
下面程序段的输出结果是( )。 publicclassTest{ publicstaticvoidmain(Stringargs[]){ intx,y; x=(int)Math.sqrt(5)/2+(int)Math.random()*5/2; Y=(int)Math.sqrt(3)/2+(int)Math.random()*3/2; if(x>y) System.out.println9"x>y"); elseif(x==y) System.out.println("x=y"); else System.out.println("x<y"); } }
A.x>y
B.x=y
C.x<y
D.编译错误
第16题:
阅读以下说明和 Java 代码,填补代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 设计 RGB 方式表示颜色的调色板,进行绘图。其类图如图 6-1 所示。该程序的 Java代码附后。图6-1 类图
【Java 代码】 //颜色类 class MyColor { private int red ,green, blue; public MyColor( ) { red = o; green = 0; blue = 0; } public MyColor(int red ,int green ,int blue) { this.red = red; this.green = green; this.blue = blue; } //其他方法略 public String toString( ) { return "Red: " + red + "\tGreen: " + green + "\tBlue " + blue; } } //调色板类 class Palette { public int number; / /颜色数 private (1)palette; //颜色表 public Palette( ) { number = 256; palette = new MyColor[number); } public Palette(MyColor[] palette ,int number) { (2)= number; (3)= palette; } //其他方法略 public String toString( ) { String str = ""; for (int i = 0; i < number; i++) { str +=i+ " : " + palette[i] + "\n"; } return str; } //绘图类 class Drawing { public (4) int COLORNUMBER = 16; public static void main(String[] args) { Palette palette; int red ,green ,blue; MyColor[] color = new MyColor[COLORNUMBER]; for (int i = 0; i < COLORNUMBER; i++) { red = (int) (Math.random( ) * 256); green = (int) (Math.random( ) * 256); blue = (int) (Math.random( ) * 256); color [i] = (5) (red ,green ,blue); } palette = new Palette(color ,COLORNUMBER); System.out.println(palette); } }
第17题:
第③段划线语句除举例子之外,还使用了哪两种说明方法?它们分别起到什么作用?(4分)
第18题:
Math.random()方法可返回介于()和()之间的一个伪随机数。
第19题:
Java语言中的方法Math.Random( )返回0到()之间的一个随机小数。
第20题:
以下()表达式产生一个0~7之间(含0,7)的随机整数。
第21题:
Math.random()方法用来实现什么功能?下面的语句起到什么作用? (int)(Math.random()*6)+
第22题:
第23题:
对
错