《大学期末考试 Java题库.docx》由会员分享,可在线阅读,更多相关《大学期末考试 Java题库.docx(19页珍藏版)》请在三一办公上搜索。
1、大学期末考试 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 = n
2、ew 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); linkedl
3、ist.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 (
4、j = 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; 4. 下面程序的运行结果是。 public class TryCatchFinally static void Proc(int sel) try if (sel = 0) System.out.println(no Exception ); return; else if (sel = 1) int
5、 i = 0; int j = 4 / i; catch (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(S
6、tring args) String s, s1 = ; char 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
7、.length - 1; i+) int k = i; for (j = 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. 下面程序的运行结果是。 public class StringTest public static void main(String args) String s1 = new String(abcde); String s2 =
8、 new String(abcde); boolean b1 = s1.equals(s2); boolean b2 = s1 = s2; System.out.print(b1 + , + b2); 8. 下面程序运行时,若输入10,则输出结果是 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; s
9、et.add(new Integer(10); set.add(new Integer(5); set.add(new Integer(15); set.add(new Integer(5); set.add(new Integer(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;
10、private int age; public int step; Dog(String s, int a) name = s; age = a; step = 0; public void run(Dog fast) fast.step+; public 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; do
11、uble add return x+y; class B extends A int x=10, y=20; double add return super.x + super.y; class Takecare public static void main(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: S
12、ystem.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 Example String str = new String(good); char ch = a, b, c; public void change(String str, char ch) str = test ok; ch0 = g; 14. public
13、 static void main(String args) Example example = new Example; example.change(example.str, example.ch); System.out.print(example.str + and ); System.out.print(example.ch); 下面程序的运行结果是。 class A public String Show(D obj) return (A and D); public String Show(A obj) return (A and A); class B extends A pub
14、lic String Show(B obj) return (B and B); public String Show(A obj) return (B and A); class C extends B public String Show(C obj) return (C and C); public String Show(B obj) return (C and B); class D extends B public String Show(D obj) return (D and D); public String Show(B obj) return (D and B); pub
15、lic class main public static void main(String args) A a1 = new A; A a2 = new B; B b = new B; C c = new C; D d = new D; System.out.println(a1.Show(b); System.out.println(a1.Show(c); System.out.println(a1.Show(d); System.out.println(a2.Show(b); System.out.println(a2.Show(c); System.out.println(a2.Show
16、(d); System.out.println(b.Show(b); System.out.println(b.Show(c); System.out.println(b.Show(d); 15. 下面程序的运行结果是。 public class Example extends TT public static void main(String args) Example t = new Example(Tom); public Example(String s) super(s); System.out.println(How do you do?); public Example this
17、(I am Tom); class TT public TT System.out.println(What a pleasure!); public TT(String s) this; System.out.println(I am + s); 16. 下面程序的运行结果是。 public class Example public static void main(String args) for (int i = 0; i 2; i+) resume: for (int j = 0; j 3; j+) for (int k = 0; k 2; k+) System.out.println
18、(i + + j + + k); if (i = 1 & k = 0) break resume; 17. 下面程序的运行结果是。 public class ATest public static void main(String args) SuperClass sb = new SubClass( ); System.out.println(sb.fun); class SuperClass int a =22, b =5; int fun return a/b; class SubClass extends SuperClass int fun return a%b; 18. 下面程序的
19、运行结果是。class TT public TT System.out.println(What a peasure!); public TT(String s) this; System.out.println(I am + s); public class Example extends TT public static void main(String args) Example example = new Example; public Example(String s) super(s); System.out.println(How do youo do?); public Exa
20、mple 。 ) this(I am Tom); 20. 下面程序的运行结果是。 public class Example public static void main(String args) int count = 0; for (int i = 0; i 3; i+) resume: for (int j = 0; j 4; j+) for (int k = 0; k 5; k+) +count; if (i = 1 & j = 2 & k = 3) break resume; System.out.println(tcount= + count); 21. 下面程序的运行结果是。 p
21、ublic 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-; public static void main(String args) A a = new A; Dog dog = a.new Dog(Tom, 3); dog.step = 30; dog.run(dog); System.out.println(dog.st
22、ep); 22. 下面程序的运行结果是。 import java.io.*; public class TestFile public static void main(String args) throws Exception BufferedReader br = new BufferedReader(new InputStreamReader(System.in); BufferedWriter bw = new BufferedWriter(new FileWriter(input.txt); String s; while (true) System.out.print(请输入一个字
23、符串: ); System.out.flush; s = br.readLine; if (s.length = 0) break; bw.write(s); bw.newLine; bw.close; 23. 下面程序的运行结果是。 class A public String Show(D obj) return (A and D); public String Show(A obj) return (A and A); class B extends A public String Show(B obj) return (B and B); public String Show(A obj
24、) return (B and A); class C extends B public String Show(C obj) return (C and C); public String Show(B obj) return (C and B); class D extends B public String Show(D obj) return (D and D); public String Show(B obj) return (D and B); public class main public static void main(String args) A a1 = new A;
25、 A a2 = new B; B b = new B; C c = new C; D d = new D; System.out.println(a1.Show(b); System.out.println(a1.Show(c); 24. System.out.println(a1.Show(d); System.out.println(a2.Show(b); System.out.println(a2.Show(c); System.out.println(a2.Show(d); System.out.println(b.Show(b); System.out.println(b.Show(
26、c); System.out.println(b.Show(d); 下面程序的运行结果是。 public class E public static void main(String args) long a=1,2,3,4; long b=100,200,300,400,500; b=a; System.out.println(数组b的长度:+b.length); System.out.println(b0=+b0); 25. 下面程序的运行结果是。 public class E3 public static void main(String args) String s=西安石油大学; c
27、har a=s.charAt(2),b=s.charAt(4); System.out.print(a); System.out.println(b); 1. 1. 说出下列程序的输出结果。 class Aclass void go System.out.println(Aclass); public class Bclass extends Aclass void go System.out.println(Bclass); public static void main(String args) Aclass a = new Aclass; Aclass a1 = new Bclass;
28、a.go; a1.go; 26. 下面程序的运行结果是。 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
29、Integer(5); System.out.println(The original contents of the linkedlist is: ); System.out.println(linkedlist); linkedlist.add(4,current); linkedlist.addFirst(First); linkedlist.addLast(Last); System.out.println(After adding elements,the linkedlist is: ); System.out.println(linkedlist); 27. 下面程序的运行结果是
30、。 class A public int f(int x) return x+1; class B extends A public int f(int x) return x*x; public class E public static void main(String args) A a=new B; int m=a.f(10); System.out.println(m); 28. 下面程序的运行结果是。 public class A class Dog private String name; private int age; public int step; Dog(String
31、s, int a) name = s; age = a; step = 5; public void run(Dog fast) fast.step+; public static void main(String args) A a = new A; Dog dog = a.new Dog(Tom, 6); dog.step = 48; dog.run(dog); System.out.println(dog.step); 29. 下面程序的运行结果是。 public class Example public static void main(String args) int count =
32、 0; for (int i = 0; i 3; i+) resume: for (int j = 0; j 2; j+) for (int k = 0; k 4; k+) +count; if (i = 2 & j = 1 & k = 3) break resume; System.out.println(tcount= + count); 30. 下面程序的运行结果是。 public class E3 public static void main(String args) char c=0; for(int i=1;i=4;i+) switch(i) case 1:c=b; System
33、.out.print(c); case 2:c=e; System.out.print(c); break; case 3:c=p; System.out.print(c); default: System.out.print(!); 31. 下面程序的运行结果是。 class A public String Show(D obj) return (A and D); public String Show(A obj) return (A and A); class B extends A public String Show(B obj) return (B and B); public S
34、tring Show(A obj) return (B and A); class C extends B public String Show(C obj) return (C and C); public String Show(B obj) return (C and B); class D extends B public String Show(D obj) return (D and D); public String Show(B obj) return (D and B); public class main public static void main(String arg
35、s) A a1 = new A; A a2 = new B; B b = new B; C c = new C; D d = new D; System.out.println(a1.Show(b); System.out.println(a1.Show(c); System.out.println(a1.Show(d); System.out.println(a2.Show(b); System.out.println(a2.Show(c); System.out.println(a2.Show(d); System.out.println(b.Show(b); System.out.pri
36、ntln(b.Show(c); System.out.println(b.Show(d); 32. 下面程序的运行结果是。 import java.util.*; public class TestList public static void main(String args) List list = new LinkedList; print(list); list.add(C); print(list); list.add(D); print(list); for (int i = 0; i 4; i+) list.add(E); print(list); static void pri
37、nt(List list) System.out.println(list= + list); System.out.print(list.size= + list.size); System.out.println(n); 33. 下面程序的运行结果是。 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); 34. 下面程序的运行结果是。 class T
38、T public TT System.out.println(What a peasure!); public TT(String s) this; System.out.println(I am + s); public class Example extends TT public static void main(String args) Example example = new Example; public Example(String s) super(s); System.out.println(How do you do?); public Example this(I am
39、 Tom); 35. 下面程序的运行结果是。 public class Test static System.out.println(Hi there); public void print System.out.println(Hello); public static void main(String args ) Test st1 = new Test; st1.print; Test st2 = new Test; st2.print; 36. 下面程序的运行结果是。 class A void operate(int c) int i; for(i=0; ic.length; i+) ci = 3*ci; class Takecare public static void main(String args) A a = new A; int b = 1, 2, 3, 4; a.operate(b); for(int i=0; ib.length; i+) System.out.println(bi); 37. 下面程序的运行结果是。 import java.io.*; public class abc public static void main(String args) String s1 = Hello;
链接地址:https://www.31ppt.com/p-3394121.html