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

package work1;
public class Work2 {
public static void main(String[] args) {
String str = "this is a test of java";
int count=0;
int index = 0;
while(true) {
int m=str.indexOf("is", index);
if(m!=-1) {
index=m+1;
count++;
}else
break;
}
System.out.println("is出现的次数:"+count);
}
}

package work1;
public class Work3 {
public static void main(String[] args) {
String str="this is a test of java";
String s[]=str.split(" ");
int count=0;
for(int i=0;i<s.length;i++){
if(s[i].equals("is")){
count++;
}
}
System.out.println("单词is出现的次数:"+count);
}
}

package work1;
public class Work4 {
public static void main(String[] args) {
String str="this is a test of java";
char s[]=str.toCharArray();
for(int i=s.length-1;i>=0;i--) {
System.out.print(s[i]);
}
}
}


package work2;
import java.util.*;
public class Work1 {
public static void main(String[] args) {
System.out.println("请输入一个字符串:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char s[] = str.toCharArray();
char asc=0;
for(int i=0;i<s.length;i++) {
asc=(char)(s[i]+3);
System.out.print(asc);
}
}
}

package work2;
public class Work2 {
public static void main(String[] args) {
int big=0,small=0,count=0;
String str="ddejidsEFALDFfnef2357 3ed";
char s[]=str.toCharArray();
for(int i=0;i<s.length;i++) {
if(s[i]>='a'&&s[i]<='z') {
small++;
}else if(s[i]>='A'&&s[i]<='Z') {
big++;
}else {
count++;
}
}
System.out.println("大写字母个数为:"+big);
System.out.println("小写字母个数为:"+small);
System.out.println("非字母个数为:"+count);
}
}

class 父类 {
}
class 子类 extends 父类 {
}
1.子类拥有父类非 private 的属性、方法。
2.子类可以拥有自己的属性和方法,即子类可以对父类进行扩展。
3.子类可以用自己的方式实现父类的方法。
this:访问本类中的属性,如果本类没有此属性则从父类中继续查找;访问本类中的方法,如果本类中没有此方法则从父类中继续查找;调用本类构造,必须放在构造方法的首行;表示当前对象。
super:访问父类中的属性;直接访问父类中的方法;调用父类构造,必须放在子类构造方法的首行。
this和super都可以调用构造方法,但两者是不可以同时出现的。
| 区别点 | this | super |
|---|---|---|
| 属性访问 | 访问本类中的属性,如果本类没有此属性则从父类中继续查找 | 访问父类中的属性 |
| 方法 | 访问本类中的方法,如果本类中没有此方法则从父类中继续查找 | 直接访问父类中的方法 |
| 调用构造 | 调用本类构造,必须放在构造方法的首行 | 调用父类构造,必须放在子类构造方法的首行 |
| 特殊 | 表示当前对象 | 无此概念 |
对象向上转型: 父类 子类对象 = 子类实例;
对象向下转型: 子类 子类对象 = (子类)父类实例;原文:https://www.cnblogs.com/zzwwll/p/11593492.html