}
2、class V1{ public int x=2;
V1(){ System.out.println(\ }
class V2 extends V1{ public int x=3;
V2(){ System.out.println(\ }
class H{
public static void main(String[] s){ V1 e1=new V2();
System.out.println(e1.x); } } 3、import java.io.*; public class abc
{ public static void main(String args[ ]) { AB s = new AB(\ System.out.println(s.toString( )); } }
class AB { String s1; String s2;
AB( String str1 , String str2 ) { s1 = str1; s2 = str2; } public String toString( ) { return s1+s2;} }
4、 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 < a.length ; i ++ ) if ( a[i]%3 = = 0 ) s += a[i] ; System.out.println(\}
}
5、 class V1{ public int x=4;
V1(){ System.out.println(\}
class V2 extends V1{
public int x=7;
V2(){ System.out.println(\}
class H{
public static void main(String[] s){ V1 e1=new V2();
System.out.println(e1.x); } }
6、class V1{ int a=3;
void m1(){ System.out.println(a); } }
class E1 extends V1{ int a=5,b=3,c;
void m2(){ System.out.println(a); } }
class H{
public static void main(String[] s){ E1 e1=new E1();
e1.m1(); e1.m2(); } }
五、阅读程序,给出程序的功能
1、public class H{
public static void main(String args[]){ Fact N=new Fact(4);
System.out.print(N.fact()); } }
class Fact{ int n;
Fact(int nn) {n=nn;} int fact(){ int i,f=1;
for(i=1;i<=n;i++) f=f*i; return f; } }
2、public class H{
public static void main(String args[]){ int i,Max,Min;
int a[]={12,67,8,98,23,56,124,55,99,100}; Max=a[0];Min=a[0]; for(i=1; i
if(a[i]>Max) Max=a[i]; }
System.out.print(Max+\} }
import java.io.*; public class abc
{ public static void main(String args[]) { SubClass sb = new SubClass( ); System.out.println(sb.max( )); } }
class SuperClass
{ int a = 10 , b = 20 ; }
class SubClass extends SuperClass
{ int max( ) { return ((a>b)?a:b); } } 3、import java.io.* ; public class abc {
public static void main(String args[ ])
{ int i , n = 10 , max = 0 , min = 0 , temp = 0; try {
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)); max = min = Integer.parseInt(br.readLine( )); } catch ( IOException e ) { } ; for ( i = 2 ; i <= n ; i ++ ) { try {
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)); temp = Integer.parseInt(br.readLine( )); if (temp > max ) max=temp; if (temp < min) min=temp;
} catch ( IOException e ) { } ; }
System.out.println(\ } }
4、import java.awt.*; public class abc
{ public static void main(String args[]) { new FrameOut(); } }
class FrameOut extends Frame
{ Button btn; FrameOut( )
{ super(\
btn = new Button(\
setLayout(new FlowLayout( )); add(btn);
setSize(300,200); show( ); } }
5、public class Sum
{ public static void main( String args[ ]) { double sum = 0.0 ;
for ( int i = 1 ; i <= 100 ; i + + ) sum += 1.0/(double) i ;
System.out.println( \ }
6、import java.io.* ; public class Reverse
{ public static void main(String args[ ]) { int i , n =10 ;
int a[ ] = new int[10]; for ( i = 0 ; i < n ; i ++ ) try {
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
a[i] = Integer.parseInt(br.readLine( )); // 输入一个整数 } catch ( IOException e ) { } ; for ( i = n-1 ; i >= 0 ; i ―― ) System.out.print(a[i]+\\ System.out.println( ); } }
五、阅读程序写结果
1、设计类A和A的派生类B,要求:
1)A有两个数据成员a和b(都为int型);B中继承了A中的a和b,又定义了自己的数据成员c(int型)。
2)为A添加含有两个参数的构造方法,对a和b初始化。 3)为B添加含有一个参数的构造方法,对c初始化。
4)完成主控方法,在主控方法中用B e1=new B(5)创建对象,把a、b、c分别初始化成3、4、5,最后输出它们的和。
2、编写一个字符界面的Java Application程序,要求如下:
1)使用字符输入流类的readLine()方法,接收键盘输入的10个整数。
2)用起泡法进行非递减排序,排序结果显示在字符界面上。
3、编写一个图形界面的Applet应用程序(HTML文件可以略去),要求如下:
1)在Applet界面上添加三个TextField组件、两个Label组件和一个Button组件,如下图所示。
2)在两个TextField组件中输入两个整数,鼠标左键单击Button组件,在第三个TextField组件中显示它们的和。
4、编写一个程序,判断输入的年是否为闰年。
5、编写一个程序,对数组中每个元素赋值,然后按逆序输出。
6、输入一个姓名,程序运行后,输出“姓名Welcome you!”.例如,输入张三,则结果为“张三Welcome you !”.
7、一个Applet程序,其功能是接收用户输入的两个整数,比较它们的大小,并在用户按下“比较”按钮后,将Applet中显示的“请先输入两个待比较的整数”,改为“两个整数中最大值是:x”,x是两个数中的最大值.
8、设计类A和A的派生类B,要求:
1)A有两个数据成员a和b(都为int型);B中继承了A中的a和b,又定义了自己的数据成员c(int型)。
2)为A添加含有两个参数的构造方法,对a和b初始化。 3)为B添加含有一个参数的构造方法,对c初始化。
4)完成主控方法,在主控方法中用B e1=new B(5)创建对象,把a、b、c分别初始化成3、4、5,最后输出它们的和。