Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/String-matching/Java/string-matching-1.java
Normal file
2
Task/String-matching/Java/string-matching-1.java
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
String string = "string matching";
|
||||
String suffix = "ing";
|
||||
32
Task/String-matching/Java/string-matching-10.java
Normal file
32
Task/String-matching/Java/string-matching-10.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
public class JavaApplication6 {
|
||||
public static void main(String[] args) {
|
||||
String strOne = "complexity";
|
||||
String strTwo = "udacity";
|
||||
stringMatch(strOne, strTwo);
|
||||
}
|
||||
|
||||
public static void stringMatch(String one, String two) {
|
||||
boolean match = false;
|
||||
if (one.charAt(0) == two.charAt(0)) {
|
||||
System.out.println(match = true); // returns true
|
||||
} else {
|
||||
System.out.println(match); // returns false
|
||||
}
|
||||
for (int i = 0; i < two.length(); i++) {
|
||||
int temp = i;
|
||||
for (int x = 0; x < one.length(); x++) {
|
||||
if (two.charAt(temp) == one.charAt(x)) {
|
||||
System.out.println(match = true); //returns true
|
||||
i = two.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
int num1 = one.length() - 1;
|
||||
int num2 = two.length() - 1;
|
||||
if (one.charAt(num1) == two.charAt(num2)) {
|
||||
System.out.println(match = true);
|
||||
} else {
|
||||
System.out.println(match = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Task/String-matching/Java/string-matching-2.java
Normal file
1
Task/String-matching/Java/string-matching-2.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
string.startsWith(suffix)
|
||||
1
Task/String-matching/Java/string-matching-3.java
Normal file
1
Task/String-matching/Java/string-matching-3.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
string.substring(0, suffix.length()).equals(suffix)
|
||||
1
Task/String-matching/Java/string-matching-4.java
Normal file
1
Task/String-matching/Java/string-matching-4.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
string.contains(suffix)
|
||||
1
Task/String-matching/Java/string-matching-5.java
Normal file
1
Task/String-matching/Java/string-matching-5.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
string.indexOf(suffix) != -1
|
||||
1
Task/String-matching/Java/string-matching-6.java
Normal file
1
Task/String-matching/Java/string-matching-6.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
string.endsWith(suffix);
|
||||
1
Task/String-matching/Java/string-matching-7.java
Normal file
1
Task/String-matching/Java/string-matching-7.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
string.substring(string.length() - suffix.length()).equals(suffix)
|
||||
6
Task/String-matching/Java/string-matching-8.java
Normal file
6
Task/String-matching/Java/string-matching-8.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
int indexOf;
|
||||
int offset = 0;
|
||||
while ((indexOf = string.indexOf(suffix, offset)) != -1) {
|
||||
System.out.printf("'%s' @ %d to %d%n", suffix, indexOf, indexOf + suffix.length() - 1);
|
||||
offset = indexOf + 1;
|
||||
}
|
||||
7
Task/String-matching/Java/string-matching-9.java
Normal file
7
Task/String-matching/Java/string-matching-9.java
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
"abcd".startsWith("ab") //returns true
|
||||
"abcd".endsWith("zn") //returns false
|
||||
"abab".contains("bb") //returns false
|
||||
"abab".contains("ab") //returns true
|
||||
int loc = "abab".indexOf("bb") //returns -1
|
||||
loc = "abab".indexOf("ab") //returns 0
|
||||
loc = "abab".indexOf("ab",loc+1) //returns 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue