Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
public static void main(String[] args) {
|
||||
String[] strings = {
|
||||
"", " ", "2", "333", ".55", "tttTTT", "5", "4444 444k"
|
||||
};
|
||||
for (String string : strings)
|
||||
System.out.println(printCompare(string));
|
||||
}
|
||||
|
||||
static String printCompare(String string) {
|
||||
String stringA = "'%s' %d".formatted(string, string.length());
|
||||
Pattern pattern = Pattern.compile("(.)\\1*");
|
||||
Matcher matcher = pattern.matcher(string);
|
||||
StringBuilder stringB = new StringBuilder();
|
||||
/* 'Matcher' works dynamically, so we'll have to denote a change */
|
||||
boolean difference = false;
|
||||
char character;
|
||||
String newline = System.lineSeparator();
|
||||
while (matcher.find()) {
|
||||
if (matcher.start() != 0) {
|
||||
character = matcher.group(1).charAt(0);
|
||||
stringB.append(newline);
|
||||
stringB.append(" Char '%s' (0x%x)".formatted(character, (int) character));
|
||||
stringB.append(" @ index %d".formatted(matcher.start()));
|
||||
difference = true;
|
||||
}
|
||||
}
|
||||
if (!difference)
|
||||
stringB.append(newline).append(" All characters are the same");
|
||||
return stringA + stringB;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
public class Main{
|
||||
public static void main(String[] args){
|
||||
String[] tests = {"", " ", "2", "333", ".55", "tttTTT", "4444 444k"};
|
||||
for(String s:tests)
|
||||
analyze(s);
|
||||
}
|
||||
|
||||
public static void analyze(String s){
|
||||
System.out.printf("Examining [%s] which has a length of %d:\n", s, s.length());
|
||||
if(s.length() > 1){
|
||||
char firstChar = s.charAt(0);
|
||||
int lastIndex = s.lastIndexOf(firstChar);
|
||||
if(lastIndex != 0){
|
||||
System.out.println("\tNot all characters in the string are the same.");
|
||||
System.out.printf("\t'%c' (0x%x) is different at position %d\n", firstChar, (int) firstChar, lastIndex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("\tAll characters in the string are the same.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import java.util.OptionalInt;
|
||||
|
||||
public final class AllSameCharacters {
|
||||
|
||||
public static void main(String[] aArgs) {
|
||||
String[] words = { "", " ", "2", "333", ".55", "tttTTT", "4444 444k" };
|
||||
for ( String word : words ) {
|
||||
analyse(word);
|
||||
}
|
||||
}
|
||||
|
||||
private static void analyse(String aText) {
|
||||
System.out.println("Examining \"" + aText + "\", which has length " + aText.length() + ":");
|
||||
|
||||
OptionalInt mismatch = aText.chars().filter( ch -> ch != aText.charAt(0) ).findFirst();
|
||||
|
||||
if ( mismatch.isPresent() ) {
|
||||
char fault = (char) mismatch.getAsInt();
|
||||
System.out.println(" Not all characters in the string are the same.");
|
||||
System.out.println(" Character \"" + fault + "\" (" + Integer.toHexString((char) fault)
|
||||
+ ") is different at index " + aText.indexOf(fault));
|
||||
} else {
|
||||
System.out.println(" All characters in the string are the same.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue