课程总结

一,类的继承格式

1.在 Java 中通过 extends 关键字可以申明一个类是从另外一个类继承而来的,一般形式如下:

class 父类 {}
class 子类 extends 父类 {}

2.可以通过子类扩展父类

3.只允许多层继承,不允许多重继承

二:方法的覆写和重载

覆写:就是指子类中定义了与父类中同名的方法,但是要考虑权限,被子类覆写的方法不能拥有比父类方法更严格的访问权限.

重载:同一个类中相同名称不同参数的方法

四.抽象类的基本概念

1.包含一个抽象方法的类必须是抽象类

2.抽象类和抽象方法都要使用abstract关键声明:

3.抽象方法只需要声明而不需要实现

实验报告

1.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码、结果截图。)

统计该字符串中字母s出现的次数。

统计该字符串中子串“is”出现的次数。

统计该字符串中单词“is”出现的次数。

实现该字符串的倒序输出。

(1)实验代码及截图

public class test {

		  public static void main(String[] args) {
String str = "this is a test of java";
char c[] = str.toCharArray() ;
int i=0;
for(char J:c) {
if(J=='s') {
i++;
}
}
System.out.println("s的数量为:"+i); }
}



(2)实验代码及截图

public class TEST2 {
public static void main(String[] args) {
String str=new String("this is a test of java");
int count=0,a=0;
while(str.indexOf("is",a)!=-1) {
count++;
a=str.indexOf("is",a)+2;
}
System.out.println("is出现的次数:"+count); } }

(3)实验代码及截图

public class Test3 {
public static void main(String[] args) {
String str = "this is a test of java";
String a[];
int count=0;
a=str.split(" ");
for(String c:a){
if(c.equals("is")){
count++;
}
}
System.out.println("单词is的数量:"+count);
}
}

(4)实验代码及截图

public class Test4 {
public static void main(String[] args) { StringBuffer str = new StringBuffer("this is a test of java");
System.out.println(str.reverse());
}
}

3.已知字符串“ddejidsEFALDFfnef2357 3ed”。输出字符串里的大写字母数,小写英文字母数,非英文字母数。

实验代码及截图

public class TEst5 {

	    public static void main(String[] args) {
String str="ddejidsEFALDFfnef2357 3ed";
int a=0,b=0,m=0;
char[] c=str.toCharArray();
for(int i=0;i<str.length();i++)
{
if(c[i]>='a'&&c[i]<='z')
{
a++;
}
else if(c[i]>='A'&&c[i]<='Z')
{
b++;
} else {
m++;
}
}
System.out.println("小写字母出现的次数:"+a);
System.out.println("大写字母出现的次数:"+b);
System.out.println("其他字符出现的字数:"+m); } }

总结:

1.第二题不太会,第一题老师上课讲过大多数,书上有这些方法,很快就能解决,

2.课后要多看书。

最新文章

  1. css常用样式
  2. SDN组网相关解决方案
  3. mysql5.x(&lt;7) sql文件导入到5.7
  4. C# 6.0那些事
  5. 重新想象 Windows 8 Store Apps (69) - 其它: 自定义启动屏幕, 程序的运行位置, 保持屏幕的点亮状态, MessageDialog, PopupMenu
  6. knockout之入门介绍
  7. zzzzz
  8. 北京哪儿有卖tods豆豆鞋的?在线等答案、、、、(类似动物园、西单等地)_百度知道
  9. easyUI datagrid 动态绑定列名称
  10. css预处理器:Sass LASS Stylus
  11. 洛谷 P2404 自然数的拆分问题
  12. codeforces618B
  13. 二、网络编程-socket之TCP协议开发客户端和服务端通信
  14. C# Windows Service 基础
  15. unable to bind listening socket for address &#39;127.0.0.1:9090&#39;: Address already in use (98)
  16. python - json/pickle
  17. ActiveMQ broker和客户端之间的确认
  18. ios开发之--数组的一些操作
  19. Go基础----&gt;go的基础学习(一)
  20. Linux下如何创建新用户

热门文章

  1. js 动态生成表格案例
  2. HashMap的相关面试题
  3. Delphi 赋值语句和程序的顺序结构
  4. Linux Shell交互式自动化运维程序
  5. win7抓带tag标记报文
  6. Idea创建多模块依赖Maven项目
  7. 【leetcode】1214.Two Sum BSTs
  8. 对elementui整体设计分析-------引用
  9. node.js入门学习(六)--express
  10. BZOJ 4881: [Lydsy1705月赛]线段游戏 动态规划 + 线段树