1、public static void main(String args ) int i, s = 0;int a = 10, 20, 30, 40, 50, 60, 70, 80, 90;for ( i = 0 ; a.len gth; i+ )if(ai % 3 = 0) s += ai;System.out.pri ntln (s= + s);请写出此程序的输出结果: s=1806、阅读以下程序import java.io.*;public class abc public static void main(String args ) AB s = new AB(Great!,l love
2、 Eclipse.);System.out.println(s.toString();class AB String s1;String s2;public AB(Stri ng stri, Stri ng str2) si = strl;s2 = str2;public Stri ng toStri ng( ) retur n si + s2;运行结果是: Great! I love Eclipse.7、阅读以下程序int i, s = 0 ;int a = 10,20,30,40,50,60,70,80,90 ; a.len gth ;if ( ai%3 = = 0 ) s += ai;+
3、s);运行结果:s = 1808、阅读以下程序a= + a + nb= + b);class SubClass exte nds SuperClass int c;SubClass(i nt aa, int bb, int cc) super(aa, bb);c = cc;class SubSubClass exte nds SubClass int a;SubSubClass( int aa, i nt bb, i nt cc) super(aa, bb, cc);A = aa + bb + cc;void show( )+a+b+nc=+c);a=60b=20c=309、以下程序的输出结果
4、为 相等 。class Stri ngTest1 public static void main(String args) Stri ng s仁hello;String s2=new String(if( s1.equals(s2) System.out.println(” 相等else System.out.println(不相等10、以下程序段的输出结果为 5 6 7 8 9 public class TestArray public static void main( Stri ng args ) int i , j ;int a = 5,9,6,8,7; a.len gth-1; i
5、+ ) int k = i;for ( j = i ; j aen gth; j+ )if ( aj ak ) k = j;int temp = ai;ai = ak;ak = temp;for ( i =0 ;aen gth;System.out.pri nt(a i+System.out.pri ntln();11、写出以下程序的功能。public class TestFile public static void main(String args) throws Exception BufferedReader br = new BufferedReader(new In putStre
6、amReader(System.i n);BufferedWriter bw = new BufferedWriter( new FileWriteString s;while (true) System.out.print(请输入一个字符串: System.out.flush();r( input.txt);s = br.readL ine(); if (s.le ngth() = 0) bw.write(s);bw.n ewL in e();bw.close();break;程序功能是:从键盘逐一输入字符串,逐一输出至 in put.txt文件中,直至输入空行。12、 阅读以下程序,写出输
7、出结果。class Animal An imal( ) System.out.pri nt (A ni mal ”); public class Dog exte nds Ani mal Dog( ) System.out.pri nt (Dog public static void main(String args) Dog sn oppy = new Dog();输出结果是:Ani mal Dog13、 以下程序的输出结果为 Peter is 17 years old!public class Person String n ame;int age;public Person( Stri
8、ng n ame, int age) this. name = n ame;this.age = age; public static void main(String args) Pers on c = new Pers on (Peter, 17);System.out.pri ntln(c.n ame + is + c.age + years old!14、以下程序的输出结果为 课程号:101课程名:JSP学分:3 .public class Course private String cNumber;private String cName;private int cUn it;pub
9、lic Course(String number, String name, int unit) eNumber = nu mber; cName = n ame;cUn it = un it; public void prin tCourse lnfo() System.out.println(” 课程号:+ cNumber + 课程名:+ cName +学分:+ cUnit);class CourseTest public static void main( Stri ng args) Course c;c = new Course(101, JSP, 3);c.pri ntCourse
10、In fo();15、以下程序的输出结果为 汤姆猫体重:20.0斤 public class Tom private float weight;private static String name;public void setWeight(float weight) this.weight = weight; private void out() System.out.println(name + 体重:+ weight + 斤Tom.name =汤姆猫Tom cat = new Tom();cat.setWeight(20);cat.out();16、以下程序的输出结果是话:6612345
11、6学校:宿中public class Father String n ame, address, tel;public Father(Stri ng n ame, int age) void out() 姓名:+ name);System.out.print(” 年龄:+ age);void outOther() System.out.print(” 家庭住址:+ address);System.out.pri nt(电话:+ tel);class Son exte nds Father String school;public Son( Stri ng n ame, int age) sup
12、er( name, age);super.out();super.outOther();System.out.println(” 学校:+ school); public static void main(String args) Son son = new Son (Tom, 15); son.address =宿城区son.school =宿中son .tel = 66123456son.o ut();17、下列程序的运行结果是 12345public class MyClass int a = 1,2, 3, 4, 5 ;for (int j = 0; j+)System.out.pri
13、 nt(aj + MyClass my = new MyClass(); my.out();18、阅读下面的程序,回答问题。import java.awt.*;import javax.swi ng.*;public class T exte nds JFrame public T ( ) super(GridLayoutContainer con=this.getC onten tPa ne();con. setLayout (new GridLayout(2,3);con. add( new JButton (acon.add(new JButton(bcdef setSize(200,
14、80);setVisible(true);public static void main(String args) new T();1画图表示程序运行后的图形界面。2则该接口名为何?接口中的方法头声明如果程序通过实现某个接口处理按钮的动作事件, 如何?答案:接口名:Actio nListe ner接口中的方法: public void action Performed(Acti onEvent e)19、阅读下面的程序,并回答问题。public static void main(String args) throws IOException BufferedReader buf= new Bu
15、fferedReader( while (true) String str = buf.readL ine();if( str.equals(quit) ) break;int x = In teger.parse In t(str);System.out.pri ntln( x*x);编译运行上面的程序:1从键盘输入5,回车后输出的结果如何?2从键盘输入quit,回车后程序执行情况如何?1252终止应用程序的运行。20、阅读下面的程序代码,并回答问题。Stri ng si = new Stri ng(abcdeString s2 = new Strin g(boolea n b1= s1.e
16、quals(s2);boolea n b2 = s1= s2;System.out.pri nt(b1+b2);程序段执行后,在命令行的输出结果如何?解释输出(1)的结果的原因?true false=”判断两个对象是否指向同一个equals方法比较两个字符串的内容是否相等;运算符“ 引用,即是否为同一个对象。21、阅读下面的程序,并回答问题。String str = buf.readL in e();编译运行上面的程序:从键盘输入10,回车后输出的结果如何?从键盘输入exit,回车后程序能正确执行吗?为什么?100不能;因为方法Integer.parselnt(str)不能将字符串exit”转
17、化为整数,抛出异常。22、写出下面的程序编译、运行后的结果。public class Testnew Stude nt(, m, 90, 88);Jack, 66, 89);new Student(Maryf, 76, 86); nametsextch in esete nglishStude nt.pri nt();class Stude nt protectedStri ngn ame;charse x;intchin ese;en glish;Stude ntn ext;static Stude nt list;Stude nt (Stri ng n ame, char sex, int
18、 chi nese, int en glish) this .n ame=n ame;this.sex=sex;this.ch in ese=ch in ese;this.e nglish=e nglish;this. next=list;list=this;static void prin t() Stude nt frien d=list;if (friend=n ull)System.out.println(The list is empty.else doSystem.out.pri ntln (frien d.toStri ng();frien d=frie nd.n ext;whi
19、le(frie nd!=n ull);public Stri ng toStri ng() return new String(name+t+sex+chinese+english);答案:n amesexchin eseen glishMaryf7686Jackm6689Tom908823、阅读下列程序:public class Sumpublic static void main( Stri ng args)int j=10;j is :+j);calculate(j);System.out.pri ntl n( At last, j is :static void calculate (
20、int j)for (int i = 0;i10;i+)j+;j in calculate() is:输出结果为: (1)j in calculate。is : (2)At last j is : (3)(1)10 ; (2) 20 ; (3)10。24、按要求填空abstract class SuperAbstractvoid a() abstract void b();abstract int c(i nt i);in terface AsSuper void x();abstract class SubAbstract exte nds SuperAbstract impleme nts
21、 AsSuper public void b( )abstract Stri ng f();public class In heritAbstract exte nds SubAbstractpublic void x( ) public int c(int i ) public String f( ) public static void main(String args)In heritAbstract in sta nee = new In heritAbstract();in sta nce.x();in sta nce.a();in sta nce.b();in sta nce.c(100);System.out.pri ntl n(i nsta nce.f();在以上这段程序中:抽象类有:SuperAbstract和(1)(写出类名)非抽象类有:(2)接口有:(3)(写出接口名)AsSuper中的x()方法是(4)方法,所以在 InheritAbstract中必须对它进行(5)(1)SuperAbstract ;(2)In heritAbstract ; AsSuper ;抽象;(5)覆盖和实现。25、