-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest7_3.java
36 lines (34 loc) · 912 Bytes
/
test7_3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Scanner;
import java.lang.String;
public class test7_3{
public static void main(String[] Args){
Scanner input = new Scanner(System.in);
System.out.println("请输入第一串字符串: ");
String x1 = input.next();
System.out.println("请输入第二串字符串: ");
String x2 = input.next();
System.out.print(sonChar(x1,x2));
}
public static boolean sonChar(String str1,String str2){
int length1 = str1.length();
int length2 = str2.length();
boolean result = false;
char sonStr = str2.charAt(0);
for(int i=0;i<=length1-length2;i++){
char parentStr = str1.charAt(i);
if(sonStr==parentStr){
for(int j=0;j<length2;j++){
if(str1.charAt(i+j)!=str2.charAt(j)){
break;
}else if(j==length2-1){
result = true;
return result;
}
}
if(i==length1-length2)
result = false;
}
}
return result;
}
}