- 3
- 0
- 约1.02万字
- 约 12页
- 2017-03-04 发布于四川
- 举报
全国软件设计大j赛ava模拟题及答案
2011 模拟 java 本科
注意:
本套模拟题主要模拟命题形式与考核范围。真实竞赛题的数量、难度可能与此套模拟题有差异。
说明:
本试卷包含两种题型:“代码填空”与“程序设计”。
填空题要求参赛选手在弄清给定代码工作原理的基础上填写缺失的部分,使得程序逻辑正确、完整。所填写的代码不多于一条语句
编程题要求选手设计的程序对于给定的输入能给出正确的输出结果。注意:在评卷时使用的输入数据与试卷中给出的实例数据可能是不同的。选手的程序必须是通用的
代码填空(满分2分)
在A B C D E F 六人中随机抽取3人中奖,要求中奖人不能重复。请完善以下代码:
public class MyTest
{
public static void main(String[] args)
{
Vector a = new Vector();
for(char i=A; i=F; i++) a.add( + i);
for(int k=0; k3; k++)
{
int d = ____________________________;
System.out.println(a.remove(d));
}
}
}
int d = (int) ((6-1-k)* Math.random());
代码填空(满分3分)
不同进制的数值间的转换是软件开发中很可能会遇到的常规问题。下面的代码演示了如何把键盘输入的3进制数字转换为十进制。试完善之。
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int n = 0;
for(int i=0; is.length(); i++)
{
char c = s.charAt(i);
if(c0 || c 2) throw new RuntimeException(Format error);
n = ______________________;
}
System.out.println(n);
(int) (n+(c-0)*Math.pow(3, (s.length()-i-1)));
代码填空(满分4分)
有如下程序,完成的功能为:找出数组中的最大元素。请填写程序的中空白,使程序运行正确。
public class test
{
public static void main(String[] args) {
int array[]={0,34,67,90,21,-9,98,1000,-78};
System.out.println(new test().findMax (array, 0));
}
public int findMax(int array[],int index)
{
if(array==null || array.length==0)
{
return 0;
}
int max=array[0];
if(indexarray.length-1)
{
max=____________________
}
if(maxarray[index]) max= array[index];
return max;
}
}
max=findMax(array, index+1);
代码填空(满分5分)
电视台开宝箱节目:打进电话的人可以开启一个宝箱。箱子中有一件礼品。礼品是iphone的机率为1/12;是mp3 的机率为1/5;是洗衣粉的机率为1/2;剩余是KFC优惠券。
每次打进电话,宝箱会重置。
以下程序模拟了该抽奖过程。请填写缺失的部分。
public static void main(String[] args)
{
int i = (int) Math.random() * _____________;
if (i 5) {
System.out.println(恭喜中了:iphone手机);
}else if (i 17) {
System.out.println(恭喜中了:mp3);
} else if (i 47) {
System.out.println(恭喜中了:洗衣粉);
} else {
System.out.println(恭喜中了:KFC优惠券);
}
}
60
代码填空(满分6分)
下列代码求出一个二进制串中连续的1或连续的0出现的最大次数。请填缺失代码。
例如:s = “101100111100011”
原创力文档

文档评论(0)