代做Java、Java作业代写、Java作业代做String类、StringBuffer类、Jbulider工具代开发

代做Java、Java作业代写、Java作业代做String类、StringBuffer类
实验五 常用API
一、实验目的及要求
1、 了解内部类的使用
2、 掌握异常类的使用
3、 理解并掌握String类、StringBuffer类
二、实验内容
(一) 内部类
运行下列程序,了解内部类的使用,分析说明运行结果。
class Cry{
public void cry(){
System.out.println("大家好");
}
}
public class KY5_1 {

public static void main(String[] args) {
Cry hello = new Cry(){
public void cry(){
System.out.println("大家好,祝大家工作顺利!");
}
};
hello.cry();
}
}
(二) 异常类
当两个数相除时,除数不能为0,若除数为0则抛出异常(Exception)。使用try…catch语句处理该异常,捕获该异常后被catch代码块处理,并打印出异常信息。不论是否发生异常都要求输出“除法中,除数是不能为0的。”。
public class KY5_2 {
public static void main(String[] args) {
//下面的代码定义了一个try…catch…finally语句用于捕获异常
{
int result = divide(4, 0); //调用divide()方法
System.out.println(result);
} { //对捕获到的异常进行处理
System.out.println("捕获的异常信息为:" + e.getMessage());
return; //用于结束当前方法
} { //填入所需关键字
System.out.println("除法中,除数是不能为0的。");
}
System.out.println("程序继续向下执行…");
}
//下面的方法实现了两个整数相除,并使用throws关键字声明抛出异常
public static int divide(int x, int y) Exception {
int result = x / y; //定义一个变量result记录两个数相除的结果
return result; //将结果返回
}
}
要求:请补全代码并将程序的源代码、运行结果写在实验报告上。

(三)String类与StringBuffer类的使用
1.利用下面的关键代码编写一个完整的程序KY5_3.java,理解String类与StringBuffer类的使用。
String s=new String("This is an demo of the String method.");
System.out.println("Length: "+s.length());
System.out.println("SubString: "+s.substring(11,15));
StringBuffer sf=new StringBuffer("Hello World!");
sf.append(" Hello Java!");
sf.insert(12," And");
System.out.println(sf);
System.out.println(sf.charAt(0));
sf.setCharAt(0,''h'');
System.out.println(sf.charAt(0));
System.out.println(sf);

2.将程序的运行结果写在实验报告中。


三、实验设备与环境
windows7及以上系统,安装eclipse+JDK
四、实验过程和结果

五、实验总结
http://www.6daixie.com/contents/9/1338.html

我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全  汇编语言 硬件编程 软件设计 工程标准规等。其中代写代做编程语言或工具包括但不限于以下范围:

C/C++/C#代写

Java代写

IT代写

Python代写

辅导编程作业

Matlab代写

Haskell代写

Processing代写

Linux环境搭建

Rust代写

Data Structure Assginment 数据结构代写

MIPS代写

Machine Learning 作业 代写

Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导

Web开发、网站开发、网站作业

ASP.NET网站开发

Finance Insurace Statistics统计、回归、迭代

Prolog代写

Computer Computational method代做

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/studentabroad/p/8969896.html