欢迎来到天天文库
浏览记录
ID:40558986
大小:45.50 KB
页数:5页
时间:2019-08-04
《Java复习重点!!》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1、写结果classStringTest1{publicstaticvoidmain(String[]args){Strings1="hello";Strings2=newString("hello");if(s1.equals(s2)){System.out.println("相等");}else{System.out.println("不相等");}}}或者publicclassIfTest{publicstaticvoidmain(Stringargs[]){intx=3;inty=1;if(x=y)System.out.println("Not
2、equal");elseSystem.out.println("Equal");}}2、写结果publicclassTestArray{publicstaticvoidmain(Stringargs[]){inti,j;inta[]={5,9,6,8,7};for(i=0;i3、i]+"");System.out.println();}3、写出以下程序的功能。importjava.io.*;publicclassTestFile{publicstaticvoidmain(Stringargs[])throwsException{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));BufferedWriterbw=newBufferedWriter(newFileWriter(“input.txt"));Strings;while(true){S4、ystem.out.print("请输入一个字符串:");System.out.flush();s=br.readLine();if(s.length()==0)break;bw.write(s);bw.newLine();}bw.close();}}4、写出结果classAnimal{Animal(){System.out.print("Animal");}}publicclassDogextendsAnimal{Dog(){System.out.print("Dog");}publicstaticvoidmain(String[]args){Dog5、snoppy=newDog();}}5、5下面程序是实现采用JDBC-ODBC的数据库连接,连接数据数据源table1,并实现查询功能,请在适当的位置填写语句。classConn{StringsDBDriver="_________________________";StringsConnStr="jdbc:odbc:table1";Connectionconnect=null;ResultSetrs=null;publicConn(){try{_______________(sDBDriver);}catch(java.lang.ClassNotFo6、undExceptione){System.err.println(e.getMessage());}}publicResultSetexecuteQuery(Stringsql){try{connect=DriverManager.getConnection(sConnStr);Statementstmt=connect.createStatement();rs=stmt.executeQuery(sql);}catch(SQLExceptionex){System.err.println(ex.getMessage());}returnrs;}}17、.阅读下面的程序,分析程序输出的结果.classLeaf{5inti=0;Leaf(inti){this.i=i;}Leafincreament(){i++;returnthis;}voidprint(){System.out.println("i="+i);}publicstaticvoidmain(String[]args){Leafleaf=newLeaf(100);leaf.increament().increament().print();}}i=1022.classStaticTest{staticintx=1;inty;StaticTes8、t(){y++;}publicstaticvoidmain(Stringargs[]){Sta
3、i]+"");System.out.println();}3、写出以下程序的功能。importjava.io.*;publicclassTestFile{publicstaticvoidmain(Stringargs[])throwsException{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));BufferedWriterbw=newBufferedWriter(newFileWriter(“input.txt"));Strings;while(true){S
4、ystem.out.print("请输入一个字符串:");System.out.flush();s=br.readLine();if(s.length()==0)break;bw.write(s);bw.newLine();}bw.close();}}4、写出结果classAnimal{Animal(){System.out.print("Animal");}}publicclassDogextendsAnimal{Dog(){System.out.print("Dog");}publicstaticvoidmain(String[]args){Dog
5、snoppy=newDog();}}5、5下面程序是实现采用JDBC-ODBC的数据库连接,连接数据数据源table1,并实现查询功能,请在适当的位置填写语句。classConn{StringsDBDriver="_________________________";StringsConnStr="jdbc:odbc:table1";Connectionconnect=null;ResultSetrs=null;publicConn(){try{_______________(sDBDriver);}catch(java.lang.ClassNotFo
6、undExceptione){System.err.println(e.getMessage());}}publicResultSetexecuteQuery(Stringsql){try{connect=DriverManager.getConnection(sConnStr);Statementstmt=connect.createStatement();rs=stmt.executeQuery(sql);}catch(SQLExceptionex){System.err.println(ex.getMessage());}returnrs;}}1
7、.阅读下面的程序,分析程序输出的结果.classLeaf{5inti=0;Leaf(inti){this.i=i;}Leafincreament(){i++;returnthis;}voidprint(){System.out.println("i="+i);}publicstaticvoidmain(String[]args){Leafleaf=newLeaf(100);leaf.increament().increament().print();}}i=1022.classStaticTest{staticintx=1;inty;StaticTes
8、t(){y++;}publicstaticvoidmain(Stringargs[]){Sta
此文档下载收益归作者所有