江西农业大学
2011
?/p>
2012
学年第一学期期末考试试卷?/p>
B
?/p>
课程名称?/p>
JAVA
?/p>
言
?/p>
?/p>
?/p>
?/p>
开课单位:软件学院
考试方式:闭?/p>
使用专业:软件工?/p>
考试日期?/p>
2011.12.27
考试时间?/p>
120
分钟
题号
一
?/p>
?/p>
总分
签名
题分
30
20
50
100
得分
注意事项?/p>
1
、本试卷?/p>
1
页,考生必须将试卷答案填写在答题纸上?/p>
2
、考试结束后,考生务必将试卷?/p>
答题纸和草稿纸交给监考老师?/p>
一、程序输出题(共
6
小题,每小题
5
分,?/p>
30
分)
1
?/p>
public class Arrays
{
public static void main(String[] args)
{
int[] a1 = { 1, 2, 3, 4, 5 };
int[] a2;
a2 = a1;
for(int i = 0; i < a2.length; i++)
a2[i]+i;
for(int i = 0; i < a1.length; i++)
System.out.println( "a1[" + i + "] = " + a1[i]);
}
}
2
?/p>
public class ArrayCopyDemo
{ public static void main(String[] args)
{ char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e', 'i', 'n', 'a', 't', 'e', 'd'};
char[] copyTo = new char[7];
System.arraycopy(copyFrom, 2, copyTo, 0, 7);
System.out.println(new String(copyTo));
}
}
3
?/p>
public class BankAccount {
private int accountNumber;
private float balance;
public BankAccount(int number, float initBal){
accountNumber = number;
balance = initBal;
}
public String toString(){
return("Account #"+new java.text.DecimalFormat("000000").format(accountNumber) + " with balance "
+ new java.text.DecimalFormat("$0.00").format(balance));
}
}
public class AccountTester {
public static void main(String args[]) {
BankAccount
anAccount;
anAccount = new BankAccount(100023,100);
System.out.println(anAccount);
}
}
4
?/p>
class A1{
int x = 20;
public void setx(int i){
x = i;
}
void printa(){
System.out.println(x);
}
}
class B1 extends A1{
int x=1;
void printb() {
super.x = super.x +10 ;
System.out.println
("super.x= " + super.x +
"
x= " + x);
}
}
public class Exam4_4Test
{
public static void main(String[] args){
A1 a1 = new A1();
a1.setx(4);
a1.printa();
B1 b1 = new B1();
b1.printb();
b1.printa();
b1.setx(6);
b1.printb();
b1.printa();
a1.printa();
}
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>
?/p>