-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava_learn.java
More file actions
85 lines (81 loc) · 2.44 KB
/
Java_learn.java
File metadata and controls
85 lines (81 loc) · 2.44 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Java_learn {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str11 = br.readLine().trim().split(" ");
String str1 = str11[0];
String str2 = str11[1];
System.out.println(getCommonStrLength(str1,str2));
}
public static String getCommonStrLength(String str1, String str2){
if(str1 == null || str2 == null){
return null;
}
if (str1.equals("") || str2.equals("")){
return null;
}
String max = "";
String min = "";
if(str1.length() < str2.length()){
max = str2;
min = str1;
} else {
max = str1;
min = str2;
}
String current = "";
for(int i = 0; i < min.length(); i++){
for(int begin = 0, end = min.length()-i; end <= min.length(); begin++,end++){
current = min.substring(begin, end);
if(max.contains(current)){
return current;
}
}
}
return null;
}
// public static void main(String[] args) {
// // TODO Auto-generated method stub
// int x = 10;
// String name = "Dirk";
// x = x * 17;
// System.out.print("x is " + x + "\n");
//
// double d = Math.random();
//
// double r = Math.rint(d*10);
// System.out.print(r);
// //**
// x = 10;
// for (int i = 0; i < x; i += 1) {
// System.out.print(i + "\n");
// //System.out.print("\n");
// }
//
// //**
// /*
// while(x > 7) {
// x -= 1;
// System.out.print("This is a valid statement." + '\n');
// }
// for (x = 0; x < 10; x += 1) {
// System.out.print("x is now " + x + "\n");
// }
// */
//
// // if/else 的条件分支测试
// x = 2;
// if (x == 10) {
// System.out.println("x must be 10.");
// } else {
// System.out.println("x is not 10.");
// }
// if ((x < 3) & (name.equals("Dirk"))) {
// System.out.println("Gently");
// }
// System.out.println("this line runs no matter what.");
//
// }
}