- 1:输出字符串"HelloWorld"的字符串长度
- 2:输出"HelloWorld"中"o"的位置
- 3:输出"HelloWorld"中从下标5出开始第一次出现"o"的位置
- 4:截取"HelloWorld"中的"Hello"并输出
- 5:截取"HelloWorld"中的"World"并输出
- 6:将字符串" Hello "中两边的空白去除后输出
- 7:输出"HelloWorld"中第6个字符"W"
- 8:输出"HelloWorld"是否是以"h"开头和"ld"结尾的。
- 9:将"HelloWorld"分别转换为全大写和全小写并输出。
- 10:创建一个类,有width,height和id属性,要求重写该类equals方法,使得该类对象在所有属性的值都相同的情况下才相等
package work001;
public class Work003 {
public static void main(String[] args) {
String a = "HelloWorld";
System.out.println(a.length());
System.out.println(a.indexOf("o"));
System.out.println(a.indexOf("o", 5));
System.out.println(a.substring(0,5));
System.out.println(a.substring(5));
String b = " Hello ";
System.out.println(b.trim());
System.out.println(a.indexOf(5));
System.out.println(a.endsWith("ld"));
System.out.println(a.startsWith("h"));
System.out.println(a.toLowerCase());
System.out.println(a.toUpperCase());
System.out.println(a.equals("HelloWorld"));
}
}
class Bwj{
private String width;
private String height;
private String id;
public String getWidth() {
return width;
}
public void setWidth(String width) {
this.width = width;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public boolean equals(String width,String id,String height) {
if(this.width.getClass()==width.getClass())
{
if(this.width==width&&this.id==id&&this.height==height) {
return true;
}
else {
return false;
}
}else {return false;}
}
}