编写一个Frame框架应用程序,要求如下: (1)在窗口设置两个菜单“文件”、“编辑” (2)在“文件”菜单里添加三个菜单项“打开”、“保存”、“关闭” (3)在“编辑”菜单里添加两个菜单项“复制”、“粘贴” (4)点击关闭菜单项时,使程序关闭。
|
|
按以下要求编写程序 (1)编写Animal接口,接口中声明run() 方法 (2)定义Bird类和Fish类实现Animal接口 (3)编写Bird类和Fish类的测试程序,并调用其中的run()方法
|
|
按以下要求编写程序 (1) 创建一个Rectangle类,添加width和height两个成员变量 (2) 在Rectangle中添加两种方法分别计算矩形的周长和面积 (3) 编程利用Rectangle输出一个矩形的周长和面积
|
|
方法重写。
|
|
方法重载
|
|
什么是继承?
|
|
java的异常处理机制。 |
|
Java的异常处理是通过5个关键词。
|
|
java中的异常。 |
|
阅读以下程序,给出程序的输出结果。
publicclassMyClass { inta[] = { 1, 2, 3, 4, 5 };
voidout() { for(intj = 0; j lt; a.length; j++) System.out.print(a[j] + quot;quot;); }
publicstaticvoidmain(String[] args) { MyClass my = newMyClass(); my.out(); } }
|
|
阅读以下程序,给出程序的输出结果。 publicclassFather { String name, address, tel; intage;
publicFather(String name, intage) { this.name= name; this.age= age; }
voidout() { System.out.print(quot;姓名:quot;+ name); System.out.print(quot; 年龄:quot;+ age); }
voidoutOther() { System.out.print(quot; 家庭住址:quot;+ address); System.out.print(quot; 电话:quot;+ tel); } }
classSon extendsFather { String school;
publicSon(String name, intage) { super(name, age); }
voidout() { super.out(); super.outOther(); System.out.println(quot; 学校:quot;+ school); }
publicstaticvoidmain(String args[]) { Son son = newSon(quot;Tomquot;, 15); son.address= quot;金水区quot;; son.school= quot;九中quot;; son.tel= quot;66123456quot;; son.out(); } }
|
|
阅读以下程序,给出程序的输出结果。 publicclassTom { privatefloatweight; privatestaticString name;
publicvoidsetWeight(floatweight) { this.weight= weight; }
privatevoidout() { System.out.println(name+ quot;体重:quot;+ weight+ quot;斤quot;); }
publicstaticvoidmain(String[] args) { Tom.name= quot;汤姆猫quot;; Tom cat = newTom(); cat.setWeight(20); cat.out(); } }
|
|
阅读以下程序,给出程序的输出结果。 publicclassCourse { privateString cNumber; privateString cName; privateintcUnit;
publicCourse(String number, String name, intunit) { cNumber= number; cName= name; cUnit= unit; }
publicvoidprintCourseInfo() { System.out.println(quot;课程号:quot;+ cNumber+ quot; 课程名:quot;+ cName+ quot; 学分:quot;+ cUnit); } }
classCourseTest { publicstaticvoidmain(String[] args) { Course c; c = newCourse(quot;101quot;, quot;ASPquot;, 3); c.printCourseInfo(); } }
|
|
以下程序的输出结果是什么? publicclassPerson { String name; intage;
publicPerson(String name, intage) { this.name= name; this.age= age; }
publicstaticvoidmain(String[] args) { Person c = newPerson(quot;Peterquot;, 17); System.out.println(c.name+ quot; is quot;+ c.age+ quot; years old!quot;); } }
|
|
阅读以下程序,写出输出结果。 class Animal { Animal() { System.out.print (quot;Animal quot;); } } public class Dog extends Animal { Dog() { System.out.print (quot;Dog quot;); }
public static void main(String[] args) { Dog snoppy= new Dog(); } }
|
|
请给出以下程序的主要功能。 import java.io.*; public class TestFile { public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txtquot;)); String s; while (true) { System.out.print(quot;请输入一个字符串: quot;); System.out.flush(); s=br.readLine(); if (s.length()==0) break; bw.write(s); bw.newLine(); } bw.close(); } }
|
|
请给出以下程序的输出结果。 public class TestArray { public static void main(String args[ ]){ int i , j ; int a[ ] = { 5,9,6,8,7}; for ( i = 0 ; i lt; a.length-1; i ++ ) { int k = i; for ( j = i ; j lt; a.length ; j++ ) if ( a[j]lt;a[k] ) k = j; int temp =a[i]; a[i] = a[k]; a[k] = temp; } for ( i =0 ; ilt;a.length; i++ ) System.out.print(a[i]+quot; quot;); System.out.println( ); } }
|
|
请给出以下程序的输出结果。 class StringTest1 { public static void main(String[] args) { String s1=quot;helloquot;; String s2=new String(quot;helloquot;); if(s1.equals(s2)){ System.out.println(quot;相等quot;); }else{ System.out.println(quot;不相等quot;); } } }
|
|
请给出以下程序的输出结果。public class TestArray{ public static void main(String args[ ]){ int i , j ; int a[ ] = { 5,9,6,8,7}; for ( i = 0 ; i < a.length-1; i ++ ) { int k = i; for ( j = i ; j < a.length ; j++ ) if ( a[j] |
|
请给出以下程序的输出结果。class StringTest1{ public static void main(String[] args) { String s1="hello"; String s2=new String("hello"); if(s1.equals(s2)){ System.out.println("相等"); }else{ System.out.println("不相等"); } }} |
|
阅读以下程序,写出输出结果。class Animal { Animal() { System.out.print ("Animal "); }}public class Dog extends Animal { Dog() { System.out.print ("Dog "); } public static void main(String[] args) { Dog snoppy= new Dog(); }} |
|
请给出以下程序的主要功能。import java.io.*;public class TestFile{ public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txt")); String s; while (true) { System.out.print("请输入一个字符串: "); System.out.flush(); s=br.readLine(); if (s.length()==0) break; bw.write(s); bw.newLine(); } bw.close(); }} |
|
写出下面程序的运行结果
import java.io.* ; public class abc { public static void main(String args[ ]) { int i, s = 0 ; int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 }; for ( i = 0 ; i lt; a.length ; i ++ ) if ( a[i]%3 = = 0 ) s += a[i] ; System.out.println(quot;s=quot;+s); } }
|
|
写出下面程序的运行结果
import java.io.*; public class abc { public static void main(String args[ ]) { AB s = new AB(quot;Hello!quot;,quot;I love JAVA.quot;); System.out.println(s.toString( )); } } class AB { String s1; String s2; publicAB(String str1, String str2) { s1 = str1; s2 = str2; } public String toString( ) { return s1+s2; } }
|
|
编写Manager类对Employee类方法的重写 class Employee { String name ; int salary; public Employee(String name,int salary){ this.name = name; this.salary = salary; } public String getDetails( ){ return quot;Name: quot;+name+quot;\nSalary: quot;+salary; } }
|
|
针对employee类重写:①equals方法②toString方法③clone方法
|
|
编写Count类的对象赋予递增的序列号,并给出测试程序。
|
|
利用包的概念,编写文件Point.java,定义了Point类放入graphic.twoD包中。
|
|
利用包的概念,编写文件TestPackage.java放在文件夹graphics下的twoD文件中,包含main()方法的测试程序。定义了一个点及一个矩形,计算并输出矩形的面积。
|
|
用if语句实现将变量ch中的小写字母变为大写字母。
|
|
用switch语句输出8月份的英文名称。
|
|
用switch语句输出一个2000年2月所包含的天数。
|
|
编程查找10以内的积为50的两个数
|
|
编写程序输出1000以内的所有奇数
|
|
编写程序输出下列结果1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6
|
|
对象 |
|
消息 |
|
类 |
|
实例 |
|
方法 |
|
结构化程序设计的优缺点 |
|
面向对象的基本思想和主要特征 |
|
描述面向对象的三个重要特性之封装性 |
|
描述面向对象的三个重要特性之继承性 |
|
描述面向对象的三个重要特性之多态性 |
|
抽象 |
|
联编 |
|
String是最基本的数据类型吗? |
|
int 和 Integer 有什么区别? |
|
String 和StringBuffer的区别? |
|
运行时异常与一般异常有何异同? |
|
final, finally, finalize的区别? |
|
Overload和Override的区别。 |
|
Overloaded的方法是否可以改变返回值的类型? |
|
abstract class和interface有什么区别? |
|
数组有没有length()这个方法? String有没有length()这个方法? |
|
接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)? |
|
是否可以继承String类? |
|
构造器Constructor是否可被override? |
|
简述Java多态性的概念,隐藏、覆盖和重载的概念及使用时应注意的问题。 |
|
swtich是否能作用在byte上,是否能作用在long上,是否能作用在String上? |
|
简述Java中接口的概念及接口的性质? |
|
简述Java中构造方法的概念及特点。 |
|
什么是事件、事件源和事件监听器?简述使用事件监听器进行事件处理的过程。 |
|
补充完整HelloWorldApplet类, 使其完成功能就是在坐标(50,10)处打印出字符串:”Hello!”;并且其可以作为一个Application运行,在控制台打印出字符串:”Hello!”(注:请加上必要的注释)
|
|
1.编程实现测试程序类Test:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?(10分) (注:满足Math.sqrt()% 1 == 0条件的是一个完全平方数)
|
|
请描述AWT事件模型并举例。
|
|
以下程序可否编译通过,如果不能,请指出其错误. public class Forest implements Serializable{ private Tree tree = new Tree();, public static void main(String[] args){ Forest f = new Forest(); try{ FileOutputStream fs = new FileOutputStream(quot;Forest.Serquot;); ObjectOutputStream os=new FileOutputStream(fs); os.writeObject(f); os.close(); }catch(Exception ex){ ex.printStackTrace(); } } } Public class Tree{ }
|
|
编写一个完整的Java Application 程序。包含接口ShapeArea,类Circle、Test,具体要求如下:(注:请加上必要的注释) ⑴接口ShapeArea: ①接口方法 double getArea():求一个形状的面积 double getPerimeter():求一个形状的周长 ⑵类Circle: 实现ShapeArea接口,并有以下属性和方法: ①属性 radius: double类型,表示圆的半径 ②方法 Circle(double r):构造函数 toString()方法 :输出圆的描述信息,如“radius=1.0, perimeter=6.28, area=3.14” ⑶Test类作为主类要完成测试功能 ①生成Circle对象 ②调用对象的toString方法,输出对象的描述信息
|
|
请编写程序,实现对数组int a[]=new a[5];用5个随机数赋初值,进行从小到大排序,并在控制台窗口输出排完序的结果。
|
|
分析下面代码执行后,写出正确的输出结果。public class Test{ public int aMethod(){ static int i=0; i++; System.out.println(i); } 在 main 方法中有以下代码: Test test = new Test(); test.aMethod(); |
|
下列语句序列执行后,k 的值是( )。int i=10, j=18, k=30;switch( j - i ){ case 8 : k++;case 9 : k+=2;case 10: k+=3;default : k/=j;} |
|
下列程序段执行后 b3 的结果是( )。boolean b1=true, b2, b3;b3= b1 ? b1 : b2; |
|
读下列程序,解释注释的语句。import java.awt.*;import java.awt.event.*;public class winClose { public static void main(String args[]) { Frame f=new Frame("这是一个窗口");//(1) f.addWindowListener(new WindowAdapter(){ //(2) public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setVisible(true);(3) }} |
|
创建一个窗体,上面有5个按钮,采用box的布局管理,在显示器上显示并输出。 |
|
创建一个带有Panel的窗体,上面有一个按钮,点击按钮可以计数。 |
|
创建一个窗体,上面放有一个标签quot;Hello World!quot;,显示并输出。 |
|
从标准输入中读取字符串,并在标准输出显示,如果遇到exit字符退出系统。 |
|
通过文件字节流实现文件farrago.txt的内容复制到outagainc.txt文件。 |
|
通过文件字符流实现文件farrago.txt的内容复制到outagainc.txt文件。 |
|
定义描述雇员信息的类EmpInfo,实例化该类的对象并进行访问。要求如下: 1)类EmpInfo含有name、designation、department三个属性;一个构造方法;一个print方法,用于输出类EmpInfo的三个属性。 2)编写一个测试类,要求创建两个对象(quot;Robert Javaquot;,quot;Managerquot;,quot;Coffee shopquot; );和(quot;Tom Javaquot;,quot;Workerquot;,quot;Coffee shopquot; );,然后用print方法输出这两个对象。
|
|
编写一个Frame框架应用程序,要求如下: (1) 在窗口设置两个菜单“文件”、“编辑” (2)在“编辑”菜单里添加两个菜单项“复制”、“粘贴”
|
|
编写一个Frame框架应用程序,要求如下: (1) 在窗口设置两个菜单“文件”、“编辑” (2) 在“文件”菜单里添加三个菜单项“打开”、“保存”、“关闭” (3)点击关闭菜单项时,使程序关闭。
|
|
按以下要求编写程序 (1) 编写Animal接口,接口中声明run() 方法 (2) 定义Bird类和Fish类实现Animal接口 (3) 编写Bird类和Fish类的测试程序,并调用其中的run()方法
|
|
编写一个完整的Java Application 程序。包含接口ShapeArea,类Circle、Test,具体要求如下:(注:请加上必要的注释)(15分) ⑴接口ShapeArea: 接口方法 double getArea():求一个形状的面积 double getPerimeter ():求一个形状的周长 ⑵类Circle: 实现ShapeArea接口,并有以下属性和方法: ① 属性 radius: double类型,表示圆的半径 ② 方法 Circle(double r):构造函数 toString()方法 :输出圆的描述信息,如“radius=1.0, perimeter=6.28, area=3.14” ⑶Test类作为主类要完成测试功能 ① 生成Circle对象 ② 调用对象的toString方法,输出对象的描述信息
|
|
请编写程序,实现对数组int a[]=new a[5];用5个随机数赋初值,使用冒泡排序法进行从小到大排序,并在控制台窗口输出排完序的结果。 |
|
用do while语句实现编程求奇数1到99得和。 |
|
编写一个Rectangle类,含有一个点(point对象),宽(width)和高(high),在其中完成下面功能(注:请加上必要的注释)。 1) 试着写至少一个构造方法; 2) 写出求矩形类的长、高、面积方法; 3) 写出实现该类定义对象得计数功能的方法,并写出主程序进行测试。
|
|
写一个Applet, 其完成功能就是在坐标(20,20)处打印出字符串:”Hello World!”;并且其可以作为一个Application运行,在控制台处打印出字符串:”Hello World!” (注:请加上必要的注释) |
|
编程实现将字符数组copyFrom{ #39;d#39;, #39;e#39;, #39;c#39;, #39;a#39;, #39;f#39;, #39;f#39;, #39;e#39;, #39;i#39;, #39;n#39;, #39;a#39;, #39;t#39;, #39;e#39;, #39;d#39; }中的内容拷贝到字符数组copyTo中,然后输出字符数组copyTo。
|
|
编程实现将字符串数组{ quot;String Onequot;, quot;String Twoquot;, quot;String Threequot; }中的每一个串转换成全部小写字母,然后按顺序输出。 |
|
使用for语句编程实现将数组{ 32, 87, 3, 589, 12, 1076, 2000, 8, 622, 127 }按顺序输出。 |
|
编程序实验从头拷贝字符串quot;Copy this string until you encounter the letter #39;g#39;.quot;直到遇到字母g,并输出拷贝结果。 |
|
读下面程序,写出程序主要功能,并给出最后屏幕输出结果。
public class String2 { public static void main(String[] args) { char ch = #39;t#39;; if (chgt;=#39;a#39; amp;amp; chlt;=#39;z#39;) ch=(char)(#39;A#39;+ch-#39;a#39;); System.out.println(quot;ch = quot;+ch); } }
|
|
编程实现判断char类型的字符#39;t#39;是大写还是小写字母,并输出判断结果The character t is lower case。 |
|
读下面程序,给出最后屏幕输出结果。 public class BitwiseDemo { static final int VISIBLE = 1; static final int DRAGGABLE = 2; static final int SELECTABLE = 4; static final int EDITABLE = 8; public static void main(String[] args) { int flags = 0; flags = flags | VISIBLE; flags = flags | DRAGGABLE; if ((flags amp; VISIBLE) == VISIBLE) { if ((flags amp; DRAGGABLE) == DRAGGABLE) { System.out.println(quot;Flags are Visible and Draggable.quot;); } } flags = flags | EDITABLE; if ((flags amp; EDITABLE) == EDITABLE) { System.out.println(quot;Flags are now also Editable.quot;); } } }
|
|
读下面程序,给出最后屏幕输出结果。 public class ShiftTest{ public static void main(String [] args){ int x=0x80000000; int y=0x80000000; x=xgt;gt;1; y=ygt;gt;gt;1; System.out.println(“0x80000000gt;gt;1 = ” + Integer.toHexString(x)); System.out.println(“0x80000000gt;gt;gt;1 = ” + Integer.toHexString(y)); } }
|
|
读下面程序,给出最后屏幕输出结果。 class Test { public static void main(String args[]) { System.out.println(“java\n语\b言quot;); System.out.println(quot;java\r语言quot;); System.out.println(quot;java\t语言quot;); System.out.println(quot;\\java语言\\quot;); System.out.println(quot;\#39;java语言\#39;quot;); System.out.println(“\”java语言\“”); } }
|
|
读下面程序,给出编号语句的注释,最后屏幕输出结果。 public class Assign { public static void main (String args[ ]) { int x, y; //1 float z=3.414f ; //声明并赋值float型变量 double w=3.1415; //声明并赋值double型变量 boolean truth=true; //声明并赋值boolean型变量 char c; //声明字符变量 String str; //2 String str1=quot;byequot;; //声明并赋值string类变量 c=#39;A#39;; //3 str=quot;Hi out therequot;; //给string变量赋值 x=6; y=1000; //给int型变量赋值 System.out.println(quot;x=quot;+x); System.out.println(quot;y=quot;+y); System.out.println(quot;z=quot;+z); System.out.println(quot;w=quot;+w); System.out.println(quot;truth=quot;+truth); System.out.println(quot;c=quot;+c); System.out.println(quot;str=quot;+str); System.out.println(quot;str1=quot;+str1); } }
|
|
编程实现将char类型的字符#39;语#39;的Unicode值输出,并转换为int类型输出,最后再将改int值转换为字符输出。 |
|
编程求自然数1到100得和。 |
|
使用Switch语句,编程实现可以输出一个年的每一个月的天数,要求程序最后根据用户输入的年输出该年2月份包含的天数。 |
|
使用Switch语句,编写可以输出12个月英文名称的程序,程序组假定一个值, 输出一个月份的英文名称。 |
|
用ifelse语句实现程序,将学时成绩等级按照ABCED输出。 |
|
编写程序按照格式输出下列结果 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6
|
|
用while语句输出1000以内的所有奇数. |
|
下面一些常用的常量的程序,请解释带编号的语句。 public class SomeConstTest{
public static void main(String args[]){
//1 System.out.println(quot;Byte.MAX_VALUE =quot;+ Byte.MAX_VALUE); System.out.println(quot;Byte.MIN_VALUE =quot;+ Byte.MIN_VALUE); System.out.println(); //输出int型的最大值与最小值 System.out.println(quot;Integer.MAX_VALUE =quot;+ Integer.MAX_VALUE); System.out.println(quot;Integer.MIN_VALUE =quot;+ Integer.MIN_VALUE); System.out.println(); //2 System.out.println(quot;Long.MAX_VALUE =quot;+ Long.MAX_VALUE); System.out.println(quot;Long.MIN_VALUE =quot;+Long.MIN_VALUE); System.out.println(); //3 System.out.println(quot;Float.MAX_VALUE =quot;+ Float.MAX_VALUE); System.out.println(quot;Float.MIN_VALUE =quot;+ Float.MIN_VALUE); System.out.println(); //4 System.out.println(quot;Double.MAX_VALUE =quot;+ Double.MAX_VALUE); System.out.println(quot;Double.MIN_VALUE =quot;+ Double.MIN_VALUE); System.out.println(); //5 System.out.println(quot;Float.POSITIVE_INFINITY =quot;+ Float.POSITIVE_INFINITY); System.out.println(quot;Float.NEGATIVE_INFINITY =quot;+ Float.NEGATIVE_INFINITY); System.out.println(); //输出double型的正无穷大与负无穷大 System.out.println(quot;Double.POSITIVE_INFINITY =quot;+ Double.POSITIVE_INFINITY); System.out.println(quot;Double.NEGATIVE_INFINITY =quot;+ Double.NEGATIVE_INFINITY); System.out.println();
//输出float型0/0 System.out.println(quot;Float.NaN =quot;+ Float.NaN); System.out.println(); //输出double型0/0 System.out.println(quot;Double.NaN =quot;+ Double.NaN); System.out.println();
}
|
|
下面基本数据类型的变量赋值的程序,请解释带编号的语句,并写出程序的运行结果。
public class Assign { public static void main (String args[ ]) { int x, y; //1 float z=3.414f ; //2 double w=3.1415; //3 boolean truth=true; //4 char c; //5 String str; //6 String str1=quot;byequot;; //7 c=#39;A#39;; //8 str=quot;Hi out therequot;; //9 x=6; y=1000; //10 System.out.println(quot;x=quot;+x); System.out.println(quot;y=quot;+y); System.out.println(quot;z=quot;+z); System.out.println(quot;w=quot;+w); System.out.println(quot;truth=quot;+truth); System.out.println(quot;c=quot;+c); System.out.println(quot;str=quot;+str); System.out.println(quot;str1=quot;+str1); } }
|
|