大学期末考试-Java题库
1. 下面程序的运行结果是( )。 public class E3{ public 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 LinkedList(); 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(“First“); 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++) if (a[j] < a[k]) k = j; int temp = a[i]; a[i] = a[k]; a[k] = temp; } for (i = 0; i < a.length; i++) System.out.print(a[i] + “ “); 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 (ArithmeticException e) { System.out.println(“Catch “); } catch (Exception e) { System.out.println(“Will not be cuted“); } 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 = ““; char c; s = “wELCOME“; for (int i = 0; i = a } 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 = i; j < a.length; j++) if (a[j] < a[k]) k = j; int temp = a[i]; a[i] = a[k]; a[k] = temp; } for (i = 0; i < a.length; i++) System.out.print(a[i] + “ “); 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 = s1.equals(s2); boolean b2 = s1 == s2; System.out.print(b1 + “,“ + b2); } }