实验二 java程序设计基础及简单类的设计资料

上传人:E**** 文档编号:107327307 上传时间:2019-10-19 格式:DOC 页数:9 大小:79KB
返回 下载 相关 举报
实验二 java程序设计基础及简单类的设计资料_第1页
第1页 / 共9页
实验二 java程序设计基础及简单类的设计资料_第2页
第2页 / 共9页
实验二 java程序设计基础及简单类的设计资料_第3页
第3页 / 共9页
实验二 java程序设计基础及简单类的设计资料_第4页
第4页 / 共9页
实验二 java程序设计基础及简单类的设计资料_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《实验二 java程序设计基础及简单类的设计资料》由会员分享,可在线阅读,更多相关《实验二 java程序设计基础及简单类的设计资料(9页珍藏版)》请在金锄头文库上搜索。

1、实验二 Java程序设计基础及简单类的设计一、实验目的1.掌握数组类型的声明和动态内存申请,理解数组的引用模型;2.掌握String类的应用及对字符串变量的操作;3.掌握类的声明格式和多种封装措施,理解对象的引用模型;4.掌握成员变量和方法的概念及构造方法的定义和使用;5.掌握方法的重载。二、实验内容1.给定一个一维整型数组,实现以下功能:(1)求数组元素中的最大值;(2)求数组元素中的最小值;(3)求某个关键字在数组中的序号,若给定关键字在数组中不存在,返回-1;(4)将数组中所有元素按升序重新排列;(5)判断数组的元素序列是否己排序;要求每个功能用一个方法实现,并编写main方法进行测试。

2、package java实验二;import java.util.Arrays;public class 实验二public static int Max(int table) int b=table0;for(int i=1;itable.length;i+)if(btablei)b=tablei;return b;public static int Min(int table) int c=table0;for(int i=1;itablei)c=tablei;return c;public static int 索引位置(int table) int index=Arrays.binar

3、ySearch(table,8); if(index=0) return -1; else return index; public static int 数组排序(int table) Arrays.sort(table); return table; public static boolean 判断排序(int table)for(int i=0;itable.length-1;i+)if(tableitablei+1)for(int j=0;jtablej+1)return false;return true;public static void main(String args) /

4、TODO 自动生成的方法存根 int a=new int2,5,6,8,0,7,9; System.out.println(数组是否已经排序:+判断排序(a);System.out.println(数组元素的最大值为:+实验二.Max(a); System.out.println(数组元素的最小值为:+实验二.Min(a); System.out.println(8的索引位置是:+实验二.索引位置(a); a=实验二.数组排序(a); System.out.print(排序后的数组: ); for(int i=0;ia.length;i+) System.out.print( ai+,); S

5、ystem.out.println(); System.out.println(数组是否已经排序:+实验二.判断排序(a);2.编写一个方法找出两个字符串中所有共同的字符,并在main方法中通过键盘输入两个字符串进行测试。package java实验二; import java.util.*;import javax.swing.*;public class 寻相同字符 public void 找相同字符(String s1,String s2)char c1 = s1.toCharArray(); char c2 = s2.toCharArray(); ArrayList lis = new

6、 ArrayList(); for(int i=0; ic1.length; i+) for(int j=0; jc2.length; j+) if(c1i = c2j ) lis.add(c1i); for(int i=0; ilis.size(); i+) for(int j=0; jlis.size(); j+) if(lis.get(i) = lis.get(j)&i!=j) lis.remove(lis.get(i); for(int i=0; i _balance) System.out.println(账户:+this._account+ 卡上余额不足,取款失败!+n + 操作时

7、间:+this.操作时间()+n ); return; this._balance = this._balance - amount; System.out.println(成功取款:+amount); checkAccount(); public Date 操作时间() Date a=new Date(); return a; public void checkAccount() /显示进行操作后的余额和操作的时间 System.out.println(账户:+this._account+ 卡上余额为:+_balance+n +操作时间:+this.操作时间()+n ); public St

8、ring getID() return _ID; public void setID(String iD) /建户人证件号码 _ID = iD; public String getAccount() return _account; public void setAccount(String account ) /新建账号名称 this._account =account ; public String getName() return _name; public void setName(String name) /建户人姓名 this._name = name; public String getAccounTimet() SimpleDateFormat sdf = new SimpleDateFormat(yyyy:MM:dd HH:mm:ss); return sdf.format(this._accounTimet);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号