77范文网 - 专业文章范例文档资料分享平台

2011最新整理Java练习题(3)

来源:网络收集 时间:2019-03-27 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

}

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,最后输出它们的和。

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库2011最新整理Java练习题(3)在线全文阅读。

2011最新整理Java练习题(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/547067.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: