(测试类)package String;
public class TestString {
public static void main(String[] args) {
String m = new String();
System.out.println("dd");
System.out.println(
"Firstly,we will check wether or not there are cat in the sentence that is The cat in the hat");
System.out.println(m.inSubString("cat", "The cat in the hat"));
System.out.println(
"Secondly,we will check wether or not there are The in the sentence that is The cat in the hat");
System.out.println(m.inSubString("The", "The cat in the hat"));
System.out.println(
"Thirdly,we will check wether or not there are hat in the sentence that is The cat in the hat");
System.out.println(m.inSubString("hat", "The cat in the hat"));
System.out.println(
"At last,we will check wether or not there are kkko in the sentence that is The cat in the hat");
System.out.println(m.inSubString("kkko", "The cat in the hat"));
}
}
package String;
public class String {
public boolean inSubString(java.lang.String string, java.lang.String string2) {
int a = "x".length();
int b = "y".length();
boolean k = false;
int i = 0;
for (int m = 0; m < b; m++) {
if ("x".charAt(i) == "y".charAt(m)) {
for (int h = i + 1; h < a; h++) {
m++;
if ("x".charAt(h) != "y".charAt(m)) {
k = false;
break;
}
else {
k = true;
continue;
}
}
continue;
}
}
return k;
}
}
一直提示找不到main方法,吐了,保存和该always都没有,求解答,
(package String) 包路径的问题,String是java中的一个常用类,不能用来做包名,换一个包名
java相关基础知识可以在补习一下,有些是内置关键字最好别用
不要自己定义String类 建议基础学习一下 了解java关键字