Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,2 +1,22 @@
// For this task consider the following strings
String string = "string matching";
String suffix = "ing";
// The most idiomatic way of determining if a string starts with another is the String.startsWith method.
string.startsWith(suffix)
// Another way is to use a combination of String.substring and String.equals
string.substring(0, suffix.length()).equals(suffix)
// To determine if a string contains at least one occurrence of another string, use the String.contains method.
string.contains(suffix)
// A slightly more idiomatic approach is String.indexOf, which also returns the index of the first character.
string.indexOf(suffix) != -1
// The most idiomatic way of determining whether a string ends with another is the String.endsWith method.
string.endsWith(suffix);
//Similarly, a combination of String.substring and String.equals can be used.
string.substring(string.length() - suffix.length()).equals(suffix)
// If you're looking to find the index of each occurrence, you can use the following.
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;
}

View file

@ -1,32 +0,0 @@
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);
}
}
}

View file

@ -1 +1,40 @@
string.startsWith(suffix)
"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
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);
}
}
}

View file

@ -1 +0,0 @@
string.substring(0, suffix.length()).equals(suffix)

View file

@ -1 +0,0 @@
string.contains(suffix)

View file

@ -1 +0,0 @@
string.indexOf(suffix) != -1

View file

@ -1 +0,0 @@
string.endsWith(suffix);

View file

@ -1 +0,0 @@
string.substring(string.length() - suffix.length()).equals(suffix)

View file

@ -1,6 +0,0 @@
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;
}

View file

@ -1,7 +0,0 @@
"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