1、5、阅读以下程序import java io. * ;public class Test 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. length; i+ )if(ai % 3 = 0) s += ai;System, out. println(ns=H + s);请写出此程序的输岀结果:s=1806、阅读以下程序import javaio.*;public class abc public static void
2、main(String args ) AB s = new ABC Great !n, T love Eclipse.n); System .out. println(s toString();class AB String si:String s2;public ABCString strl String str2) word版木si = strl;s2 = str2;public String toString( ) return si + s2;运行结果是:Great! 1 love Eclipse7、 阅读以下程序int i, s = 0 ;int a = 10 , 20 , 30 ,
3、 40 , 50 , 60 , 70 , 80 , 90 ; a. length ;if ( ai%3 = = 0 ) s += ai;System. out. println(us=n+s);运行结果:s = 1808、 阅读以下程序System, out. println(ha=n + a + Hnb= + b);class SubClass extends Superclass int c;SubClass(int aa, int bb, int cc) supcrCaa, bb);c = cc;class SubSubClass extends SubClass int a;SubSu
4、bClass(int aa, int bb, int cc) super(aa, bb, cc);A = aa + bb + cc;)void show( )System, out. printlnCa=” +a+nnb=, +b+nnc=u +c);a=60b=20c=309以下程序的输出结果为 相等 。class StringTcstl public static void main(String args) String sl=hello;String s2=new String(,hellon);if( si.equals(s2) ) System.out.println(H相等”);
5、 else System, out. println(n 不相等);args ) 10 以下程序段的输出结果为 5 6 7public class TestArray public static void main(Stringint i , j ;int a = 5, 9,6, & 7; a. length-1; i + ) word版木 int k = i;for ( j = i ; j a.length; j+ ) if ( aj 逐一输出至input, txt文件中 直至输入空行。12、阅读以下程序,写出输出结果。class Animal AnimalC ) System, out.
6、print (Animal n); public class Dog extends Animal Dog( ) System, out. print CDog n);public static void main(String! args) Dog snoppy = new Dog():输出结果是:Animal Dog13 以下程序的输出结果为 Peter is 17 years old! 。public class Person String name;int age;public Pcrson(String name, int age) thisname = name;this, age
7、 = age;public static void main(StringL args) Person c = new PersonPeter”,17);System .out. printlnCcname + H is n + c. age + ” years old!);14、以下程序的输出结果为 课程号:101课程名:JSP学分:3.public class Course private String cNuinber;private String cNamc;private int cUnit;public Course(String number, String name, int
8、unit) cNuniber = niunbcr;cNanic = name;cUnit 二 unit;public void printCourscInfoO System, out. println(n课程号:+ cNuniber + 课程名:+ cNamc +学分:+ cUnit);class CourscTcst Course c;c = new CourseClOr, JSP, 3);c. printCourseInfo();15、以下程序的输出结果为 汤姆猫体重:20.0斤 public class Tom private float weight;private static S
9、tring name;public void setWcight(float weight) this, weight = weight;private void out() System, out. println(name + 体重:+ weight + 斤Tom. name = 11 汤姆猫11;Tom cat = new TomO;cat. setWeight ); catout();16、以下程序的输出结果是 一:Tom年龄:15家庭住址:宿城区:66123456学校:宿中一。public class Father String name, address, tel;public F
10、ather(String name, int age) void out() System. out print(n:n + name);System, out. print(n 年龄:+ age);void outOtherO System, out. print(n 家庭住址:+ address);System, out. print(n + tel);class Soil extends Father String school:public Son(String name, int age) super(name, age);superout();super outOtherO;Sys
11、tem, out. println(n 学校:11 + school);public static void inain(String args) Son son = new Son(Tom”, 15);son. address 二”宿城区”;son. school =宿中;son. tel = 66123456soil out( );17、下列程序的运行结果是 12345。public class MyClass int a = 1, 2, 3, 4, 5 ;for (int j = 0; j+) System, out. print(a j + ,M,);MyClass my = new
12、MyClassO;my. out(); 18、阅读下面的程序,回答问题。import java.awt.*;import javax.swing*;public class T extends JFrame public T ( ) super(uGridLayoutn);Container con=this gctContentPaneC); con. sctLayout(new GridLciyout(2, 3); con. a(ld(new JButton(,an);WORD版木 con. add(new JButton(,rbH);con. add (new JButton(,cu);
13、con.add(new JButton(d”);con. add(new JButton(,eH);con. add(new JButton(,r fH);setSizc(200, 80);setVisible(true);public static void mainCString args) new TO;1画图表示程序运行后的图形界面。2如果程序通过实现某个接口处理按钮的动作事件,则该接口名为何?接口中的方法头声明如何?答案:接口名:ActionListcncr接口中的方法:public void actionPcrfonncd(ActionEvent c)19、阅读下面的程序,并回答问
14、趣。public static void main(String args) throws IOException BuffercdReadcr buf=ncw BuffercdReadcrCnew InputStreamRcadcr(System. in);St ring str = buf rwdLinc();if( str. equalsCquit”) break;int x = IntegerparseInt(str);System out println(x*x);WORD版木 编译运行上面的程序:1从键盘输入5,回车后输出的结果如何?2从键盘输入quit,回车后程序执行情况如何?1
15、252终止应用程序的运行。20、 阅读下面的程序代码,并回答问题。String si = new StringCbcde11);String s2 = new String(,Tabcde11);boolean bl= slcquals(s2);boolean b2 = sl= s2;System, out. print(bl+n ”+b2);1程序段执行后,在命令行的输出结果如何?2解释输出(1)的结果的原因?签案:1true false2equals方法比较两个字符串的容是否相等;运算符判斷两个对象是否指向同一个 引用,即是否为同一个对象。21、 阅读下面的程序,并回答问趣。public
16、static void mainCString args) throws IOException BuffcrcdReadcr buf=ncw BuffcrcdReadcr(new InputStreainRcadcr(Systcm. in);String str = bufrcadLinc();if( str. equals(quit) ) break;int x = Integerparsclnt(str);编译运行上面的程序:1从键盘输入10,回车后输出的结果如何?2从键盘输入exit,回车启程序能正确执行吗?为什么?100不能;因为方法Integer, parse I nt (str)
17、不能将字符串“exit”转化为整数,抛出异常。22 -写出下面的程序编译、运行后的结果。public class Testpublic static void main(String args) new StudcntCTom, * nf , 90, 88);new StudentJack, nf , 66, 89);new StudentCMary, * f, 76, 86);System out printlnCliainctscxtchincsctcngl ish”);Student print();class Student protectedStringname;protcctcdc
18、harsex;intChinese;english;Studentnext;static Student 1ist;Student (String name, char sex, int Chinese, int english)this. name二name;this sex二sex;this Chinese二Chinese;this, english二english;this. next=list;list=this;static void printO Student friend=list;if (fricnd=null)System .out. print lnC* The list
19、 is empty.u): else doSystem out println(fricnd toStringO); fricnd=friend. next;while(fricnd!=null);Ipublic String toStringO return new String(name+,tu +sex+Htn +chincse+n t +engl ish);答案namesex Chineseeng1ishMaryf 7686Jackin 6689Tornm 908823、阅读下列程序:public class Suinpublic static void main(String arg
20、s)int j=10;System, out. println(n j is : n+j);calculate(j);System, out. println(nAt last, j is :static void calculate (int j)for (int i = 0;i10;i+)j+;System .out. print ln(n j in calculateO is: M + j);输出结果为:j is : (1)j in calculateO is : (2)At last j is : (3)答案:(1) 10 : (2) 20 ; (3) 10 o24、按要求填空abst
21、ract class SupcrAbstractlvoid a()abstract void b();abstract int c(int i);interface AsSupcr void x();abstract class SubAbstract extends SupcrAbstract iniplcinents AsSupcr public void b( )abstract String f();public class InheritAbstract extends SubAbstractpublic void x( ) public int c(int i ) public String f( ) public static void main(String args)InheritAbstract instance = new InhcritAbstract();instance x( );instance a();instance b( );instance. c(100);System. out println(instance f();在以上这段程序中:AsSuper中的x()方法是(4)方法,所以在InhcritAbstract中必须对它进行(5)(1)SuperAbstract ;(2)InheritAbstract ;(3)AsSup
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1