发布时间 : 星期一 文章2011-2012山东大学Java高级程序语言期末考试题(含答案)更新完毕开始阅读817a4989cc22bcd126ff0c93
2012年Java试题答案(2012-1-12)
一、选择题
CDBAD CCBDC ABDCD CBDDC
二、读程序题(4选3)
1. 8分
4 10 20 34 52
2. 8分
4 5 6 7 15 16 17 8 14 19 18 9 13 12 11 10
(1) 8分
Level 1 beginning. Level 2 beginning. zone: A number: 370 processing0
Improper numeric value processing1
Improper code length processing2 processing3
Exception Unknown Level 1 ending.
3. 8分
2134 2431 2413 3124 3412 3421 4213 4312
三、写程序题()
1. 6分 public class WriteOne { public static void main(String[] args) { int i, mulRs, last3; for (i = 100; i <= 999; i++) { mulRs = (int) Math.pow(i, 2); last3 = mulRs % 1000; if (last3 == i) System.out.println(i); } } } 2. 14分
//请在此处完成对抽象类中相关方法的定义 public abstract double getArea(); //请在此书写代码,将继承自父类的name属性赋值为“Circle” super(\//请在此完成构造方法,并且将继承自父类的name属性赋值为“Rectangle” super(\this.width = width; this.length = length; //从方法的定义开始,请在此完整的完成求矩形面积的方法 public double getArea() { return width * length; } //请在此完成对数组s []的定义 Shape[] s = new Shape[2]; 3. 16分
//在链表开始的位置插入data数值为newData的节点( head = new ListNode(addData, head);
//返回整个链表中节点的个数 int count = 0; ListNode position = head; while (position != null) { count++; position = position.link; } return count; // 寻找一个链表的节点中data数值等于vdata的节点,并在此节点后插入一个新的节点,其data的数值为newdata
ListNode position = head; int dataAtPosition; while (position != null) { dataAtPosition = position.data; if (dataAtPosition== newdata) { position.link=new ListNode(newData, position.link); break; } position = position.link; } if(position == null) System.out.println(\// 删除链表的所有节点中data数值小于max的节点( if (head != null) { while ((head.data < max) && (head.link != null)) head = head.link; ListNode position = head; if ((position.link == null) && (head.data < max)) {
head = null; return; } while (position.link != null) { if (position.link.data < max) position.link = position.link.link; else position = position.link; } } else System.out.println(\(1)