1、java 程序阅读三、阅读程序,写出程序的输出结果(每题5分,共20分)1、class A private int privateVar; A(int _privateVar) privateVar=_privateVar;boolean isEqualTo(A anotherA) if(this.privateVar = anotherA.privateVar) return true; else return false; public class B public static void main(String args) A a = new A(1); A b = new A(2);
2、System.out.println(a.isEqualTo(b); 程序的输出结果为:_false_ 2、class A double f(double x, double y) return x * y; class B extends A double f(double x, double y) return x + y; public class Test public static void main(String args) B obj = new B(); System.out.println(The program output is + obj.f(4, 6); 程序的输出结
3、果为:_ The program output is 10_3、public class Unchecked public static void main(String args) try method(); catch (Exception e) System.out.println(A); finally System.out.println(B); static void method() try wrench(); System.out.println(C); catch (ArithmeticException e) System.out.println(D); finally S
4、ystem.out.println(E); System.out.println(F); static void wrench() throw new NullPointerException(); 程序的输出结果为:EAB4、public class Test public static void main(String args) int x; int a = 0, 0, 0, 0, 0, 0 ; calculate(a, a5); System.out.println(the value of a0 is + a0); System.out.println(the value is a5
5、 is + a5); static int calculate(int x, int y) for (int i = 1; i x.length; i+) if (y 10 ); public static void main(String arg) int i=10; Test t= new Test(); t.printValue(i); 输出将是什么? CA. 8 B. 9 C. 10 D. 1130. 给出下面的代码片断 1 String str = null; 2 if (str != null) & (str.length() 10) 3 System.out.println(mo
6、re than 10); 4 5 else if (str != null) & (str.length() =0; j-) if(1 j) & i) != 0) System.out.print(1); else System.out.print(0); System.out.println();/换行 A)00000000000000000000000000000001B)00000000000000000000000000000010C)00000000000000000000000000001111D)00000000000000000000000000000000【答案】B7. 应用
7、程序的main方法中有以下语句,则输出的结果是 ( )。int x=122,33,55,678,-987; int max=x0; for(int i=1;imax) max=xi; System.out.println(max);A) 678 B) 122 C) -987 D) 33 【答案】A8.下列语句序列执行后,k 的值是( )。 int x=2, y=5, k=0; switch( x%y ) case 0: k=x+y; break; case 1: k=x-y; break; case 2: k=x*y; break; default: k=x/y; break; System.
8、out.println(k);A) 2 B) 5 C) 10 D) 0 【答案】C9. 下面的程序输出的结果是( )public class A implements B public static void main(String args) int i; A c1 = new A(); i= c1.k; System.out.println(i=+i); interface B int k = 10; A) i=0 B) i=10 C) 程序有编译错误 D) i=true【答案】B10应用程序的main方法中有以下语句,则输出的结果是 ( )。int b=1, 2, 3, 4,5, 6,7
9、; int sum=0; for(int i=0;ib.length;i+) for(int j=0;jbi.length;j+) sum+=bij; System.out.println(sum=+sum);A) 28 B)6 C) 9 D) 13 【答案】A12.编译和运行下面的应用程序,并在命令行界面输入12345,则回车后屏幕输出的结果是( ).public class A public static void main(String args) throws IOException BufferedReader buf=new BufferedReader( new InputStr
10、eamReader(System.in); String str=buf.readLine(); int x=Integer.parseInt(str); System.out.println(x/100); A) 45 B)5 C) 123 D) 12345【答案】C13.下面的程序段执行后输出的结果是( )。 StringBuffer buf=new StringBuffer(Beijing2008); buf.insert(7,); System.out.println(buf.toString();A)Beijing2008 B)Beijing2008 C) Beijing2008D)
11、 Beijing#2008 【答案】A14. 下面的程序编译运行后输出的结果是( )。public class A implements Runnable public static void main(String argv) A a = new A(); Thread t = new Thread(a); t.start(); public void run() while(true) try Thread.currentThread().sleep(1000); catch(InterruptedException e) System.out.println(e.toString(); System.out.println(looping while); A) 在屏幕上重复输出looping while。B) 在屏幕上输出一次looping while。C) 没有结果输出。 D) 以上说法都错误。【答案】A
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1