《大学期末考试Java题库.doc》由会员分享,可在线阅读,更多相关《大学期末考试Java题库.doc(22页珍藏版)》请在金锄头文库上搜索。
1、1. 下面程序的运行结果是( )。public class E3public static void main(String args) String s=大大; char a=s.charAt(2),b=s.charAt(4); System.out.print(a); System.out.println(b); 2. 下面程序的运行结果是( )。import java.util.*;public class LinkedListExample public static void main(String args)LinkedList linkedlist = new LinkedLis
2、t(); linkedlist.add(new Integer(1);linkedlist.add(new Integer(2);linkedlist.add(new Integer(3);linkedlist.add(new Integer(4);linkedlist.add(new Integer(5);System.out.println(The original contents of the linkedlist is: );System.out.println(linkedlist);linkedlist.add(2,hello); linkedlist.addFirst(Firs
3、t); linkedlist.addLast(Last); System.out.println(After adding elements,the linkedlist is: );System.out.println(linkedlist);答:3. 下面程序的运行结果是( )。public class TestArray public static void main(String args) int i, j;int a = 5, 9, 6, 8, 7 ;for (i = 0; i a.length-1; i+) int k = i;for (j = i; j a.length; j+
4、)if (aj ak)k = j;int temp = ai;ai = ak;ak = temp;for (i = 0; i a.length; i+)System.out.print(ai + );System.out.println();4. 下面程序的运行结果是( )。public class TryCatchFinally static void Proc(int sel) try if (sel = 0) System.out.println(no Exception );return; else if (sel = 1) int i = 0;int j = 4 / i; catch
5、 (ArithmeticException e) System.out.println(Catch ); catch (Exception e) System.out.println(Will not be executed); finally System.out.println(finally);public static void main(String args) Proc(0);Proc(1);5. 下面程序的运行结果是( )。public class welcomeTest public static void main(String args) String s, s1 = ;c
6、har c;s = wELCOME;for (int i = 0; i = a & c = z) s1 = s1 + Character.toUpperCase(c); else s1 = s1 + Character.toLowerCase(c);System.out.println(s1);6. 下面程序的运行结果是( )。public class arrTest public static void main(String args) int i, j;int a = 2, 1, 4, 8;for (i = 0; i a.length - 1; i+) int k = i;for (j
7、= i; j a.length; j+)if (aj ak)k = j;int temp = ai;ai = ak;ak = temp;for (i = 0; i a.length; i+)System.out.print(ai + );System.out.println();7. 下面程序的运行结果是( true,false)。public class StringTest public static void main(String args) String s1 = new String(abcde);String s2 = new String(abcde);boolean b1 =
8、 s1.equals(s2);boolean b2 = s1 = s2;System.out.print(b1 + , + b2); 8. 下面程序运行时,若输入10,则输出结果是( )。public class test public static void main(String args) throws IOException BufferedReader buf = new BufferedReader(new InputStreamReader(System.in);while (true) String str = buf.readLine();if (str.equals(qui
9、t)break;int x = Integer.parseInt(str);System.out.println(x * x);System.out.println(“OK”);9. 下面程序的运行结果是( )。public class T public static void main(String args) Set set = new HashSet();set.add(new Integer(10);set.add(new Integer(5);set.add(new Integer(15);set.add(new Integer(5);set.add(new Integer(10);
10、System.out.println(size = + set.size();Iterator it = set.iterator();while (it.hasNext() System.out.print(it.next() + );10. 下面程序的运行结果是( )。public class A class Dog private String name;private int age;public int step;Dog(String s, int a)name = s;age = a;step = 0;public void run(Dog fast)fast.step+;publ
11、ic static void main(String args)A a = new A();Dog dog = a.new Dog(Tom, 3);dog.step = 25;dog.run(dog);System.out.println(dog.step);11. 下面程序的运行结果是( )。class A int x=1, y=2;double add() return x+y; class B extends Aint x=10, y=20;double add() return super.x + super.y; class Takecare public static void m
12、ain(String args)A a = new A();B b = new B();System.out.println(a.add=+a.add();System.out.println(b.add=+b.add();12. 下面程序的运行结果是( )。for (int i = 0; i 5; i+) switch (i) default:System.out.print(defaultt);case 0:System.out.print(zerot);i+;break;case 1:System.out.print(onet);case 2:System.out.print(twot);i+;13. 下面程序的运行结果是( )。public class Exa