} }
若在dos命令行输入:java Exp1 cHINA,则输出为 。 30.阅读以下程序:String is:java import java.io.*;
public class AboutFile{ public static void main(String[ ] args){ BufferedReader b=new BufferedReader (new InputStreamReader(System.in)); String s; System.out.flush(); s=b.readLine(); System.out.println(“String is:”+s); } }
运行以上程序,若从键盘输入: java<回车>
则输出结果为 。 31.阅读以下程序,写出输出结果。Animal Cat class Animal { Animal() {
System.out.print (\ \ } }
public class Cat extends Animal { Cat() {
System.out.print (\ }
public static void main(String[] args) { Cat kitty= new Cat(); } }
32.阅读以下程序,输出结果为 1 //就是阿拉伯数字1 import java.io.*;
public class ATest{
public static void main(String args[]) { SubClass sb = new SubClass( );
System.out.println(sb.funOfMod( )); } }
class SuperClass{ int a = 10 , b = -3 ; }
class SubClass extends SuperClass{ int funOfMod( ) { return a%b; } }
33.以下程序段的输出结果为 int,int 。 class Cruncher{
。 void crunch( int i ){ System.out.print(“int”); } void crunch(String s){ System.out.print(“String”); }
public static void main(String args[ ]){ Cruncher crun=new Cruncher ( ); char ch=’h’; int i=12; crun.crunch(ch);
System.out.print(“,”); crun.crunch(i); } }
34.阅读以下程序,输出结果为 cooljava import java.io.*;
public class TestString
{ public static void main(String args[ ])
{ StringC s = new StringC (\ System.out.println(s); } }
class StringC { String s1; String s2;
StringC( String str1 , String str2 ) { s1 = str1; s2 = str2; } public String toString( ) { return s1+s2;} }
35.写出以下程序的运行结果。 s1!=s2 class StringTest1 {
public static void main(String[] args) { String s1=\ String s2=new String(\ if(s1==s2){ System.out.println(\ }else{ System.out.println(\ } }
36、以下程序的输出结果为 false,true public class EqualsMethod { public static void main(String[] args) { Integer n1 = new Integer(12);
。 。 Integer n2 = new Integer(12); System.out.print(n1= =n2); System.out.print(“,”); System.out.println(n1! =n2); } }
37、以下程序的输出结果为 one,three 。 class LabelBreak{ public static void main(String[] args) { int x=20; Label1: { System.out.print(“one,”); if ( x>10) break Label1; System.out.print(“two,”); } System.out.println(“three”); } }
。
38、写出以下程序的功能。输出文件newfile.java中的内容 import java.io.*; class FileApp{ public static void main(String[ ] args) throws IOException{ int b; FileInputStream fileIn=new FileInputStream(“newfile.java”); while((b=fileIn.read())!=-1){ System.out.print((char)b); } } }
39、以下程序的输出结果为 题目错了吧,没法做. class Test{ static int num; int c; public Test( ){ num++; } public static void main(String[ ] args){ System.out.print(x.num); Test x=new Test(); System.out.print(x.num);//告诉老师,这里错了,因为不能同时定义三个相同名字的对象的 Test x=new Test(); System.out.println(x.num); } }
。
40、以下程序的输出结果为 AB 。 class A{ public A(){ System.out.print(“ A ”); } }
public class B extends A{ public B(){ System.out.print(“ B ”); } public static void main(String[ ] args){ new B( ); } }
四、编程题 注:编程题我都是没编译的
1、编写一个输出\to Java World!\的Applet程序和嵌入该Applet的HTML页面。
① // Welcome.java
import java.applet.*;
import java.awt.Graphics;
public class Wel extends Applet{
int x,y;
public void init(){ System.out.println(); } public void paint(Graphics g){ g.drawString(\ } }
②//Welcome.html
3、2010年南非世界杯将于2010年6月6日开幕,为实现世界杯天数倒计时,假定一年360天,每月30天。编写一个完整的Java Application 程序。包含接口CupWorld及Football类,具体要求如下: ⑴接口CupWorld:
year: int类型,表示开幕的年份 month: int类型,表示开幕的月份 day: int类型,表示开幕的天 int whatday:求天数的方法 void printday():输出天数方法
⑵类Football: 实现ShapeArea接口,另有以下属性和方法: ①属性
nowyear: int类型,表示现在的年份 mowmonth: int类型,表示现在的月份 mowday: int类型,表示现在的天 ②方法
Football (int a, int b, int c):构造函数
4、编写一个简单的JAVA Applet应用程序,
1:创建一个类Rectangle,添加属性长weidth、宽heigth。 2:在Rectangle中添加两个方法,计算矩形的周长与面积。
3:再创建一个Applet子类作为主类AP1,在类体中调用类Rectangle的方法计算长=20、宽=10的矩形周长与面积并输出。 2、编写一个输出\欢迎使用JAVA语言!\的程序,用两种方式实现(Application、Applet)。 ①Application ②Applet 5、编写一个简单的JAVA Application 应用程序,编写两个方法area1,area2计算圆柱体的表面积和体积,圆柱体半径R=5,高H=10,并输出计算结果。
6、编写一个简单的JAVA Application 应用程序,计算e=1+1/1!+1/2!+1/3!+……1/20!,并输出计算结果。