《JAVA程序阅读题.doc》由会员分享,可在线阅读,更多相关《JAVA程序阅读题.doc(24页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateJAVA程序阅读题JAVA程序阅读题四、程序阅读题:(每小题6分,共18分)1写出以下程序的运行结果。 public class EqualOrNot public static void main(String args) B b1=new B(5);B b2=new B(5);System.out.println(b1=b2);System.out.println
2、(b1.equals(b2);class B int x;B( int y) x=y; 1、写出以下程序的运行结果。class StaticTest static int x=1;int y;StaticTest()y+;public static void main(String args ) StaticTest st=new StaticTest(); System.out.println(x= + x); System.out.println(st.y= + st.y); st=new StaticTest(); System.out.println(st.y= + st.y); st
3、atic x+;x=2st y=1st y=12、写出以下程序的功能。public class TestArray public static void main(String args ) int i , j ;int a = 1,3,2,5,4; for ( i = 0 ; i a.length-1; i + ) int k = i; for ( j = i ; j ak ) k = j; int temp =ai; ai = ak;ak = temp; for ( i =0 ; ia.length; i+ ) System.out.print(ai+ ); System.out.prin
4、tln( );5 4 3 2 13、写出以下程序的运行结果。class MyException extends Exceptionpublic String toString( )return negative; public class ExceptionDemopublic static void mySqrt(int a) throws MyExceptionif( a0 )throw new MyException();System.out.println(Math.sqrt(a); public static void main( String args )trymySqrt(25
5、);mySqrt(-5 );catch( MyException e )System.out.println(Caught +e);5.0Caught negative2写出以下程序的运行结果。import java.io.*;public class TestString public static void main(String args ) StringC s = new StringC (“Hello ,World!); System.out.println(s); class StringC String s1; String s2; StringC( String str1 ,
6、String str2 ) s1 = str1; s2 = str2; public String toString( ) return s1+s2;HelloWorld!4写出以下程序的功能。class Test public static void main(String args) String s;char c;int upper,lower;upper=lower=0;s=args0;for (int i=0;i=a & c=A & c=Z)upper+;System.out.println(upper+”,”+lower);1写出以下程序的运行结果。class OverloadDe
7、mo void testOverload( int i ) System.out.println(“int”); void testOverload(String s) System.out.println(“String”); public static void main(String args ) OverloadDemo a=new OverloadDemo ( ); char ch=x;a.testOverload(ch); int2阅读以下程序,写出输出结果。class Firstpublic First()aMethod();public void aMethod()System
8、.out.println(“in First class”);public class Second extends Firstpublic void aMethod()System.out.println(“in Second class”);public static void main(String args)new Second( );in Second class3写出以下程序的运行结果。import java.io.*;public class UseLabelpublic static void main(String args)Loop: for(int i=2; i10; i
9、+) for(int j=2;ji;j+) if( i%j = 0)continue Loop; System.out.print(i+ ); 2 3 5 71、写出以下程序的运行结果。publicclassChangeStrDemo publicstaticvoidchangestr(Stringstr) str=welcome; publicstaticvoidmain(Stringargs) Stringstr=1234; changestr(str); System.out.println(str); 12343、写出以下程序的运行结果。publicclassFooDemo stati
10、cbooleanfoo(charc) System.out.print(c); returntrue; publicstaticvoidmain(Stringargs) inti=0; for(foo(a);foo(b)&(i2);foo(c) i+; foo(d); abdcbdcb1写出以下程序的运行结果。public class Test1 public static void changeStr(String str)str=welcome;public static void main(String args) String str=1234;changeStr(str);System.out.println(str);12341、写出以下程序的运行结果。public class Incpublic static void main(String argv)Inc inc = new Inc();int i =0;inc.fermin(i);i = i+;System.out.println(i);void fermin(int i)i+;0-